Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4041906imm; Mon, 17 Sep 2018 07:20:19 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdat9yrjWVbtwEbgct27ip+MMdDDEoXRVrZzqVe8Q2qGYzf4ebnTh46GIsHHXbYNh9Jz3Q6P X-Received: by 2002:a63:6485:: with SMTP id y127-v6mr23358741pgb.393.1537194019363; Mon, 17 Sep 2018 07:20:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537194019; cv=none; d=google.com; s=arc-20160816; b=AI4i7Yzou9yktfBxV5JKwgXpXkHZtheKaCFJJwQzuIR3yoijZG4httX8Wd/7/Hq3dD IMaGIurEnw0eHRcKCwZ1fXbhI0Cy83YbUtjRqMHKrEaRbLVgxt56AHjKfb8IKFpGU6Ht BjbMJfHlWRQrw7g+L4NAxvTMUxVgga30WtCMrWuOqDzxyjW59ZZoan8V/qC2g5VntVOd VtWYTWUGTvVXmL4UbMX1QRX7/3WOk2BRNTeV7Cov0SH8i2/HTabnmBauXTDclqCI/Ds6 g4b+MeUz4jnaR5fFqXjYnRRf4ytPOCV6ndUJOaCHthvv+6aGXt4Ha/fAOHr6kUO15fr6 E3QA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=l9u5yS9YGBOlI2a3pg43GNDTQasmydrJVi9oRbRWKn4=; b=gkvqhcdUnyBFIG8/7J8PlFQuj0kkz41hC6J/1B9ki1r/VuBvxjLzj1CcUhJ4W039pF Lo/DeEwyhcV8ZirxfjRTA8bGsWEMazzx/XJB033dGwmU3P/Dv5knmRwoEPR8P4cLsfkb uYWAQeUf+tFp2n/2JGRef6lW+2el0B9yOzUeElWCsXuv+N7/jxEYT+YuyaSpuoOow+Ub lFANJYaYIUGd84H8kpcv0/4Od7WenKpfnh5nM51rJxQ8xKB9GjvnMok7+ObbSzgHP8O7 4hLnT+mroDK8kL6DNWE4v1AOi2Vuh6mUYAHNjBsJ0vHRLv6M5D428bdVf8as17OIhFSS zuQQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q8-v6si15299647pgh.675.2018.09.17.07.20.03; Mon, 17 Sep 2018 07:20:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728696AbeIQTr2 (ORCPT + 99 others); Mon, 17 Sep 2018 15:47:28 -0400 Received: from mail-qt0-f196.google.com ([209.85.216.196]:32807 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728465AbeIQTr1 (ORCPT ); Mon, 17 Sep 2018 15:47:27 -0400 Received: by mail-qt0-f196.google.com with SMTP id r37-v6so15429174qtc.0 for ; Mon, 17 Sep 2018 07:19:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version; bh=l9u5yS9YGBOlI2a3pg43GNDTQasmydrJVi9oRbRWKn4=; b=fo/AwlSpn5vRVGJt7xmr8UZ6S7+EwjSE9jCH6ZNOQ4PbXG8usnHpqfOOn1sgUX4ytt mRRVKxDwcWXuLMVErLOrN10/gyMRAIByKV9Dei5uT2MuUc5u8yR437DVg/UKPVXhI+jD Lb+x9atIajfgPEkHHORJZHtlendBU07j+QcvbLi6WUVD7Ynyl7W/KFaxkovivJF0rm1H yYcj4w3PFnV1pAUqwGbGiNt9qtGvAOc1jiGZWixZZvv1tYLe185lOAaWWMhhV8EArzFw weRIspFB0Vp5LPtyupqLZFJihmuofPJp2sala9KSWjq/m4OHakN93mE0C/AQpNeoI9YE CXkw== X-Gm-Message-State: APzg51AotrFUKijNzfoxNWltSNmipDSSDQRXwKCzNsNbsVrWoV7+yRc3 yOKEgnXbV53hU478BXauQVFKcA== X-Received: by 2002:a0c:95f7:: with SMTP id t52-v6mr17846185qvt.246.1537193994158; Mon, 17 Sep 2018 07:19:54 -0700 (PDT) Received: from [172.25.130.148] (pool-128-6-36-179.nat.rutgers.edu. [128.6.36.179]) by smtp.gmail.com with ESMTPSA id n25-v6sm7711127qtp.94.2018.09.17.07.19.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Sep 2018 07:19:53 -0700 (PDT) From: "Zi Yan" To: "Kirill A. Shutemov" Cc: "Andrew Morton" , "Vegard Nossum" , linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, "Naoya Horiguchi" , "Vlastimil Babka" , "Andrea Arcangeli" Subject: Re: [PATCHv2] mm, thp: Fix mlocking THP page with migration enabled Date: Mon, 17 Sep 2018 10:19:51 -0400 X-Mailer: MailMate (2.0BETAr6121) Message-ID: <899A7C0D-26EB-4FEF-A9DB-02E134ED841A@cs.rutgers.edu> In-Reply-To: <20180917133816.43995-1-kirill.shutemov@linux.intel.com> References: <20180917133816.43995-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=_MailMate_77024829-9149-44E2-8585-7FAB1DBDD09D_="; micalg=pgp-sha512; protocol="application/pgp-signature" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is an OpenPGP/MIME signed message (RFC 3156 and 4880). --=_MailMate_77024829-9149-44E2-8585-7FAB1DBDD09D_= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On 17 Sep 2018, at 9:38, Kirill A. Shutemov wrote: > A transparent huge page is represented by a single entry on an LRU list= =2E > Therefore, we can only make unevictable an entire compound page, not > individual subpages. > > If a user tries to mlock() part of a huge page, we want the rest of the= > page to be reclaimable. > > We handle this by keeping PTE-mapped huge pages on normal LRU lists: th= e > PMD on border of VM_LOCKED VMA will be split into PTE table. > > Introduction of THP migration breaks[1] the rules around mlocking THP > pages. If we had a single PMD mapping of the page in mlocked VMA, the > page will get mlocked, regardless of PTE mappings of the page. > > For tmpfs/shmem it's easy to fix by checking PageDoubleMap() in > remove_migration_pmd(). > > Anon THP pages can only be shared between processes via fork(). Mlocked= > page can only be shared if parent mlocked it before forking, otherwise > CoW will be triggered on mlock(). > > For Anon-THP, we can fix the issue by munlocking the page on removing P= TE > migration entry for the page. PTEs for the page will always come after > mlocked PMD: rmap walks VMAs from oldest to newest. > > Test-case: > > #include > #include > #include > #include > #include > > int main(void) > { > unsigned long nodemask =3D 4; > void *addr; > > addr =3D mmap((void *)0x20000000UL, 2UL << 20, PROT_READ | PROT_WRITE= , > MAP_PRIVATE | MAP_ANONYMOUS | MAP_LOCKED, -1, 0); > > if (fork()) { > wait(NULL); > return 0; > } > > mlock(addr, 4UL << 10); > mbind(addr, 2UL << 20, MPOL_PREFERRED | MPOL_F_RELATIVE_NODES,= > &nodemask, 4, MPOL_MF_MOVE); > > return 0; > } > > [1] https://lkml.kernel.org/r/CAOMGZ=3DG52R-30rZvhGxEbkTw7rLLwBGadVYeo-= -iizcD3upL3A@mail.gmail.com > > Signed-off-by: Kirill A. Shutemov > Reported-by: Vegard Nossum > Fixes: 616b8371539a ("mm: thp: enable thp migration in generic path") > Cc: [v4.14+] > Cc: Zi Yan > Cc: Naoya Horiguchi > Cc: Vlastimil Babka > Cc: Andrea Arcangeli > --- > mm/huge_memory.c | 2 +- > mm/migrate.c | 3 +++ > 2 files changed, 4 insertions(+), 1 deletion(-) > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > index 533f9b00147d..00704060b7f7 100644 > --- a/mm/huge_memory.c > +++ b/mm/huge_memory.c > @@ -2931,7 +2931,7 @@ void remove_migration_pmd(struct page_vma_mapped_= walk *pvmw, struct page *new) > else > page_add_file_rmap(new, true); > set_pmd_at(mm, mmun_start, pvmw->pmd, pmde); > - if (vma->vm_flags & VM_LOCKED) > + if ((vma->vm_flags & VM_LOCKED) && !PageDoubleMap(new)) > mlock_vma_page(new); > update_mmu_cache_pmd(vma, address, pvmw->pmd); > } > diff --git a/mm/migrate.c b/mm/migrate.c > index d6a2e89b086a..9d374011c244 100644 > --- a/mm/migrate.c > +++ b/mm/migrate.c > @@ -275,6 +275,9 @@ static bool remove_migration_pte(struct page *page,= struct vm_area_struct *vma, > if (vma->vm_flags & VM_LOCKED && !PageTransCompound(new)) > mlock_vma_page(new); > > + if (PageTransHuge(page) && PageMlocked(page)) > + clear_page_mlock(page); > + > /* No need to invalidate - it was non-present before */ > update_mmu_cache(vma, pvmw.address, pvmw.pte); > } > -- = > 2.18.0 Thank you for the patch. Reviewed-by: Zi Yan -- Best Regards Yan Zi --=_MailMate_77024829-9149-44E2-8585-7FAB1DBDD09D_= Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- Comment: GPGTools - https://gpgtools.org iQEcBAEBCgAGBQJbn7gHAAoJEEGLLxGcTqbMAtMIAJhhq7gAYdDlkf2IbQ8h3rGV 0Xi9sn44v7wMc3ToNgepO9PXpF0MGAEQ9/MaZawrPR7MtTiiMxAI6WGF0O62Pji3 2WKyEMN1SyGLk5wGaqLmZplzuDhanSlemjNK7R2zvtEeyEBATDDacTw3gnKfmsx5 MwqEvtdcctOQQMQrwEMgxoXGegrmYgrmHesoOrC+cvg6dVIpAnAcbczkRg5U7U2T NpBdBxwuz3WSFFaZLphiG5gUCBZLztXtD5GoepQ4Q0iuuukJElUtbj0XcxAH1liw dPP8Jb/S6QhxfU9RPGUcj3LHVROux6bbXOhLHZfMby3bmlnyATbIASf5ZQnFssU= =ZICK -----END PGP SIGNATURE----- --=_MailMate_77024829-9149-44E2-8585-7FAB1DBDD09D_=--