On Fri, Jun 14, 2019 at 11:22:04AM -0700, Song Liu wrote: > This patch is (hopefully) the first step to enable THP for non-shmem > filesystems. > > This patch enables an application to put part of its text sections to THP > via madvise, for example: > > madvise((void *)0x600000, 0x200000, MADV_HUGEPAGE); > > We tried to reuse the logic for THP on tmpfs. The following functions are > renamed to reflect the new functionality: > > collapse_shmem() => collapse_file() > khugepaged_scan_shmem() => khugepaged_scan_file() > > Currently, write is not supported for non-shmem THP. This is enforced by > taking negative i_writecount. Therefore, if file has THP pages in the > page cache, open() to write will fail. To update/modify the file, the > user need to remove it first. > > An EXPERIMENTAL config, READ_ONLY_THP_FOR_FS, is added to gate this > feature. Please document explicitly that the feature opens local DoS attack: any user with read access to file can block write to the file by using MADV_HUGEPAGE for a range of the file. As is it only has to be used with trusted userspace. We also might want to have mount option in addition to Kconfig option to enable the feature on per-mount basis. -- Kirill A. Shutemov