Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1423097AbbD2Pzi (ORCPT ); Wed, 29 Apr 2015 11:55:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38081 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965633AbbD2Pzf (ORCPT ); Wed, 29 Apr 2015 11:55:35 -0400 Message-ID: <5540FED0.1070007@redhat.com> Date: Wed, 29 Apr 2015 17:54:56 +0200 From: Jerome Marchand User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: "Kirill A. Shutemov" , Andrew Morton , Andrea Arcangeli , Hugh Dickins CC: Dave Hansen , Mel Gorman , Rik van Riel , Vlastimil Babka , Christoph Lameter , Naoya Horiguchi , Steve Capper , "Aneesh Kumar K.V" , Johannes Weiner , Michal Hocko , Sasha Levin , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCHv5 04/28] mm, thp: adjust conditions when we can reuse the page on WP fault References: <1429823043-157133-1-git-send-email-kirill.shutemov@linux.intel.com> <1429823043-157133-5-git-send-email-kirill.shutemov@linux.intel.com> In-Reply-To: <1429823043-157133-5-git-send-email-kirill.shutemov@linux.intel.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="AQ1Mfdmg1FFD6oQMGhbm41BFq361wWoLO" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4308 Lines: 119 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --AQ1Mfdmg1FFD6oQMGhbm41BFq361wWoLO Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable On 04/23/2015 11:03 PM, Kirill A. Shutemov wrote: > With new refcounting we will be able map the same compound page with > PTEs and PMDs. It requires adjustment to conditions when we can reuse > the page on write-protection fault. >=20 > For PTE fault we can't reuse the page if it's part of huge page. >=20 > For PMD we can only reuse the page if nobody else maps the huge page or= > it's part. We can do it by checking page_mapcount() on each sub-page, > but it's expensive. >=20 > The cheaper way is to check page_count() to be equal 1: every mapcount > takes page reference, so this way we can guarantee, that the PMD is the= > only mapping. >=20 > This approach can give false negative if somebody pinned the page, but > that doesn't affect correctness. >=20 > Signed-off-by: Kirill A. Shutemov > Tested-by: Sasha Levin Acked-by: Jerome Marchand > --- > include/linux/swap.h | 3 ++- > mm/huge_memory.c | 12 +++++++++++- > mm/swapfile.c | 3 +++ > 3 files changed, 16 insertions(+), 2 deletions(-) >=20 > diff --git a/include/linux/swap.h b/include/linux/swap.h > index 0428e4c84e1d..17cdd6b9456b 100644 > --- a/include/linux/swap.h > +++ b/include/linux/swap.h > @@ -524,7 +524,8 @@ static inline int page_swapcount(struct page *page)= > return 0; > } > =20 > -#define reuse_swap_page(page) (page_mapcount(page) =3D=3D 1) > +#define reuse_swap_page(page) \ > + (!PageTransCompound(page) && page_mapcount(page) =3D=3D 1) > =20 > static inline int try_to_free_swap(struct page *page) > { > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > index 534f353e12bf..fd8af5b9917f 100644 > --- a/mm/huge_memory.c > +++ b/mm/huge_memory.c > @@ -1103,7 +1103,17 @@ int do_huge_pmd_wp_page(struct mm_struct *mm, st= ruct vm_area_struct *vma, > =20 > page =3D pmd_page(orig_pmd); > VM_BUG_ON_PAGE(!PageCompound(page) || !PageHead(page), page); > - if (page_mapcount(page) =3D=3D 1) { > + /* > + * We can only reuse the page if nobody else maps the huge page or it= 's > + * part. We can do it by checking page_mapcount() on each sub-page, b= ut > + * it's expensive. > + * The cheaper way is to check page_count() to be equal 1: every > + * mapcount takes page reference reference, so this way we can > + * guarantee, that the PMD is the only mapping. > + * This can give false negative if somebody pinned the page, but that= 's > + * fine. > + */ > + if (page_mapcount(page) =3D=3D 1 && page_count(page) =3D=3D 1) { > pmd_t entry; > entry =3D pmd_mkyoung(orig_pmd); > entry =3D maybe_pmd_mkwrite(pmd_mkdirty(entry), vma); > diff --git a/mm/swapfile.c b/mm/swapfile.c > index 6dd365d1c488..3cd5f188b996 100644 > --- a/mm/swapfile.c > +++ b/mm/swapfile.c > @@ -887,6 +887,9 @@ int reuse_swap_page(struct page *page) > VM_BUG_ON_PAGE(!PageLocked(page), page); > if (unlikely(PageKsm(page))) > return 0; > + /* The page is part of THP and cannot be reused */ > + if (PageTransCompound(page)) > + return 0; > count =3D page_mapcount(page); > if (count <=3D 1 && PageSwapCache(page)) { > count +=3D page_swapcount(page); >=20 --AQ1Mfdmg1FFD6oQMGhbm41BFq361wWoLO Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJVQP7QAAoJEHTzHJCtsuoChrYH/32xucRXxoHc1CBBA5yUYOGZ zxg3R9tDcG5j4JBejjgrF9fsZLCgKey7T1ARfqmHQKy4sjW5bc5TX39yoP2lTqnw 9cexlNDSf7et8ocmovZG9kx4UAsTiflXtV7JggMPAqJbhQMuWeX3/kVXsMf8tmdR Du0hh8Ukx1BYJmEZcXJA6V9tZAbAhhnh75iO1PKkp9RPEwHqXsDiaDmYId8anWtJ GFBvRa846dxA7XAWiXAokXxoJnWA7KoEutxGm06oeuAGlG1rowONtL+47Bcem1P2 3V23vIBeyb82ArdFLOrj7VijyGwXQbUPScA971r7/PJsuiwyY+4UGjE4+xv8odY= =CNbG -----END PGP SIGNATURE----- --AQ1Mfdmg1FFD6oQMGhbm41BFq361wWoLO-- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/