lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <fb468c74-7da3-8b2c-e98e-ebb12793846e@nvidia.com>
Date:   Thu, 12 Nov 2020 14:08:56 -0800
From:   Ralph Campbell <rcampbell@...dia.com>
To:     Zi Yan <ziy@...dia.com>, <linux-mm@...ck.org>,
        Matthew Wilcox <willy@...radead.org>
CC:     "Kirill A . Shutemov" <kirill.shutemov@...ux.intel.com>,
        Roman Gushchin <guro@...com>,
        Andrew Morton <akpm@...ux-foundation.org>,
        <linux-kernel@...r.kernel.org>, <linux-kselftest@...r.kernel.org>,
        Yang Shi <shy828301@...il.com>,
        Michal Hocko <mhocko@...nel.org>,
        John Hubbard <jhubbard@...dia.com>,
        David Nellans <dnellans@...dia.com>
Subject: Re: [RFC PATCH 5/6] mm: truncate: split thp to a non-zero order if
 possible.


On 11/11/20 12:40 PM, Zi Yan wrote:
> From: Zi Yan <ziy@...dia.com>
> 
> To minimize the number of pages after a truncation, when truncating a
> THP, we do not need to split it all the way down to order-0. The THP has
> at most three parts, the part before offset, the part to be truncated,
> the part left at the end. Use the non-zero minimum of them to decide
> what order we split the THP to.
> 
> Signed-off-by: Zi Yan <ziy@...dia.com>
> ---
>   mm/truncate.c | 22 ++++++++++++++++++++--
>   1 file changed, 20 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/truncate.c b/mm/truncate.c
> index 20bd17538ec2..6d8e3c6115bc 100644
> --- a/mm/truncate.c
> +++ b/mm/truncate.c
> @@ -237,7 +237,7 @@ int truncate_inode_page(struct address_space *mapping, struct page *page)
>   bool truncate_inode_partial_page(struct page *page, loff_t start, loff_t end)
>   {
>   	loff_t pos = page_offset(page);
> -	unsigned int offset, length;
> +	unsigned int offset, length, left, min_subpage_size = PAGE_SIZE;

Maybe use "remaining" instead of "left" since I think of the latter as the length of the
left side (offset).
  
>   	if (pos < start)
>   		offset = start - pos;
> @@ -248,6 +248,7 @@ bool truncate_inode_partial_page(struct page *page, loff_t start, loff_t end)
>   		length = length - offset;
>   	else
>   		length = end + 1 - pos - offset;
> +	left = thp_size(page) - offset - length;
>   
>   	wait_on_page_writeback(page);
>   	if (length == thp_size(page)) {
> @@ -267,7 +268,24 @@ bool truncate_inode_partial_page(struct page *page, loff_t start, loff_t end)
>   		do_invalidatepage(page, offset, length);
>   	if (!PageTransHuge(page))
>   		return true;
> -	return split_huge_page(page) == 0;
> +
> +	/*
> +	 * find the non-zero minimum of offset, length, and left and use it to
> +	 * decide the new order of the page after split
> +	 */
> +	if (offset && left)
> +		min_subpage_size = min_t(unsigned int,
> +					 min_t(unsigned int, offset, length),
> +					 left);
> +	else if (!offset)
> +		min_subpage_size = min_t(unsigned int, length, left);
> +	else /* !left */
> +		min_subpage_size = min_t(unsigned int, length, offset);
> +
> +	min_subpage_size = max_t(unsigned int, PAGE_SIZE, min_subpage_size);
> +
> +	return split_huge_page_to_list_to_order(page, NULL,
> +				ilog2(min_subpage_size/PAGE_SIZE)) == 0;
>   }

What if "min_subpage_size" is 1/2 the THP but offset isn't aligned to 1/2?
Splitting the page in half wouldn't result in a page that could be freed
but maybe splitting to 1/4 would (assuming the THP is at least 8x PAGE_SIZE).

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ