<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
</head>
<body>
<div>
<div dir="auto">Yeah, sure go ahead.
<div dir="auto"><br>
</div>
<div dir="auto">It's just that I am out of office because of COVID-19 and won't be able to help if it goes up in flames :)</div>
<div dir="auto"><br>
</div>
<div dir="auto">Cheers,</div>
<div dir="auto">Christian</div>
</div>
<div class="x_gmail_extra"><br>
<div class="x_gmail_quote">Am 24.03.2020 11:03 schrieb "Thomas Hellström (VMware)" <thomas_os@shipmail.org>:<br type="attribution">
</div>
</div>
</div>
<font size="2"><span style="font-size:11pt;">
<div class="PlainText"><br>
<br>
On 3/4/20 11:28 AM, Thomas Hellström (VMware) wrote:<br>
> In order to reduce CPU usage [1] and in theory TLB misses this patchset enables<br>
> huge- and giant page-table entries for TTM and TTM-enabled graphics drivers.<br>
><br>
> Patch 1 and 2 introduce a vma_is_special_huge() function to make the mm code<br>
> take the same path as DAX when splitting huge- and giant page table entries,<br>
> (which currently means zapping the page-table entry and rely on re-faulting).<br>
><br>
> Patch 3 makes the mm code split existing huge page-table entries<br>
> on huge_fault fallbacks. Typically on COW or on buffer-objects that want<br>
> write-notify. COW and write-notification is always done on the lowest<br>
> page-table level. See the patch log message for additional considerations.<br>
><br>
> Patch 4 introduces functions to allow the graphics drivers to manipulate<br>
> the caching- and encryption flags of huge page-table entries without ugly<br>
> hacks.<br>
><br>
> Patch 5 implements the huge_fault handler in TTM.<br>
> This enables huge page-table entries, provided that the kernel is configured<br>
> to support transhuge pages, either by default or using madvise().<br>
> However, they are unlikely to be inserted unless the kernel buffer object<br>
> pfns and user-space addresses align perfectly. There are various options<br>
> here, but since buffer objects that reside in system pages typically start<br>
> at huge page boundaries if they are backed by huge pages, we try to enforce<br>
> buffer object starting pfns and user-space addresses to be huge page-size<br>
> aligned if their size exceeds a huge page-size. If pud-size transhuge<br>
> ("giant") pages are enabled by the arch, the same holds for those.<br>
><br>
> Patch 6 implements a specialized huge_fault handler for vmwgfx.<br>
> The vmwgfx driver may perform dirty-tracking and needs some special code<br>
> to handle that correctly.<br>
><br>
> Patch 7 implements a drm helper to align user-space addresses according<br>
> to the above scheme, if possible.<br>
><br>
> Patch 8 implements a TTM range manager for vmwgfx that does the same for<br>
> graphics IO memory. This may later be reused by other graphics drivers<br>
> if necessary.<br>
><br>
> Patch 9 finally hooks up the helpers of patch 7 and 8 to the vmwgfx driver.<br>
> A similar change is needed for graphics drivers that want a reasonable<br>
> likelyhood of actually using huge page-table entries.<br>
><br>
> If a buffer object size is not huge-page or giant-page aligned,<br>
> its size will NOT be inflated by this patchset. This means that the buffer<br>
> object tail will use smaller size page-table entries and thus no memory<br>
> overhead occurs. Drivers that want to pay the memory overhead price need to<br>
> implement their own scheme to inflate buffer-object sizes.<br>
><br>
> PMD size huge page-table-entries have been tested with vmwgfx and found to<br>
> work well both with system memory backed and IO memory backed buffer objects.<br>
><br>
> PUD size giant page-table-entries have seen limited (fault and COW) testing<br>
> using a modified kernel (to support 1GB page allocations) and a fake vmwgfx<br>
> TTM memory type. The vmwgfx driver does otherwise not support 1GB-size IO<br>
> memory resources.<br>
><br>
> Comments and suggestions welcome.<br>
> Thomas<br>
><br>
> Changes since RFC:<br>
> * Check for buffer objects present in contigous IO Memory (Christian König)<br>
> * Rebased on the vmwgfx emulated coherent memory functionality. That rebase<br>
>    adds patch 5.<br>
> Changes since v1:<br>
> * Make the new TTM range manager vmwgfx-specific. (Christian König)<br>
> * Minor fixes for configs that don't support or only partially support<br>
>    transhuge pages.<br>
> Changes since v2:<br>
> * Minor coding style and doc fixes in patch 5/9 (Christian König)<br>
> * Patch 5/9 doesn't touch mm. Remove from the patch title.<br>
> Changes since v3:<br>
> * Added reviews and acks<br>
> * Implemented ugly but generic ttm_pgprot_is_wrprotecting() instead of arch<br>
>    specific code.<br>
> Changes since v4:<br>
> * Added timings (Andrew Morton)<br>
> * Updated function documentation (Andrew Morton)<br>
> Changes since v6:<br>
> * Fix drm build error with !CONFIG_MMU<br>
><br>
> [1]<br>
> The below test program generates the following gnu time output when run on a<br>
> vmwgfx-enabled kernel without the patch series:<br>
><br>
> 4.78user 6.02system 0:10.91elapsed 99%CPU (0avgtext+0avgdata 1624maxresident)k<br>
> 0inputs+0outputs (0major+640077minor)pagefaults 0swaps<br>
><br>
> and with the patch series:<br>
><br>
> 1.71user 3.60system 0:05.40elapsed 98%CPU (0avgtext+0avgdata 1656maxresident)k<br>
> 0inputs+0outputs (0major+20079minor)pagefaults 0swaps<br>
><br>
> A consistent number of reduced graphics page-faults can be seen with normal<br>
> graphics applications, but due to the aggressive buffer object caching in<br>
> vmwgfx user-space drivers the CPU time reduction is within the error marginal.<br>
><br>
> #include <unistd.h><br>
> #include <string.h><br>
> #include <sys/mman.h><br>
> #include <xf86drm.h><br>
><br>
> static void checkerr(int ret, const char *name)<br>
> {<br>
>    if (ret < 0) {<br>
>      perror(name);<br>
>      exit(-1);<br>
>    }<br>
> }<br>
><br>
> int main(int agc, const char *argv[])<br>
> {<br>
>      struct drm_mode_create_dumb c_arg = {0};<br>
>      struct drm_mode_map_dumb m_arg = {0};<br>
>      struct drm_mode_destroy_dumb d_arg = {0};<br>
>      int ret, i, fd;<br>
>      void *map;<br>
><br>
>      fd = open("/dev/dri/card0", O_RDWR);<br>
>      checkerr(fd, argv[0]);<br>
><br>
>      for (i = 0; i < 10000; ++i) {<br>
>        c_arg.bpp = 32;<br>
>        c_arg.width = 1024;<br>
>        c_arg.height = 1024;<br>
>        ret = drmIoctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &c_arg);<br>
>        checkerr(fd, argv[0]);<br>
><br>
>        m_arg.handle = c_arg.handle;<br>
>        ret = drmIoctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &m_arg);<br>
>        checkerr(fd, argv[0]);<br>
>        <br>
>        map = mmap(NULL, c_arg.size, PROT_READ | PROT_WRITE, MAP_SHARED, fd,<br>
>               m_arg.offset);<br>
>        checkerr(map == MAP_FAILED ? -1 : 0, argv[0]);<br>
><br>
>        (void) madvise((void *) map, c_arg.size, MADV_HUGEPAGE);<br>
>        memset(map, 0x67, c_arg.size);<br>
>        munmap(map, c_arg.size);<br>
><br>
>        d_arg.handle = c_arg.handle;<br>
>        ret = drmIoctl(fd, DRM_IOCTL_MODE_DESTROY_DUMB, &d_arg);<br>
>        checkerr(ret, argv[0]);<br>
>      }<br>
>      <br>
>      close(fd);<br>
> }<br>
><br>
> Cc: Andrew Morton <akpm@linux-foundation.org><br>
> Cc: Michal Hocko <mhocko@suse.com><br>
> Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org><br>
> Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com><br>
> Cc: Ralph Campbell <rcampbell@nvidia.com><br>
> Cc: "Jérôme Glisse" <jglisse@redhat.com><br>
> Cc: "Christian König" <christian.koenig@amd.com><br>
> Cc: Dan Williams <dan.j.williams@intel.com><br>
><br>
><br>
> _______________________________________________<br>
> dri-devel mailing list<br>
> dri-devel@lists.freedesktop.org<br>
> <a href="https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Fdri-devel&amp;data=02%7C01%7Cchristian.koenig%40amd.com%7Cbd52811a941244ba8b9908d7cfda99cb%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637206410124474022&amp;sdata=642fi4213qtdqtYCFfPNesOIDGmoYBuR4PeEzWMyfKE%3D&amp;reserved=0">
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Fdri-devel&amp;data=02%7C01%7Cchristian.koenig%40amd.com%7Cbd52811a941244ba8b9908d7cfda99cb%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637206410124474022&amp;sdata=642fi4213qtdqtYCFfPNesOIDGmoYBuR4PeEzWMyfKE%3D&amp;reserved=0</a><br>
<br>
Hi, Christian,<br>
<br>
I think this should be OK to merge now. Is it OK if I ask Dave to pull <br>
this separately?<br>
<br>
Thanks,<br>
<br>
Thomas<br>
<br>
<br>
</div>
</span></font>
</body>
</html>