Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5917621imm; Wed, 12 Sep 2018 13:10:46 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdabl5d5hxsMPMzwFTBKrgPI1joN1grvhcxM5ajdN2kqXC4tt59iYenOUldBM/eWH2WgAJz4 X-Received: by 2002:a63:d613:: with SMTP id q19-v6mr4030955pgg.327.1536783046846; Wed, 12 Sep 2018 13:10:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536783046; cv=none; d=google.com; s=arc-20160816; b=oxZ4+Lq2l9AOkfXklPlCzmf4jRljWWOc0I9MUtBWn9Kf9P2SMFm+D6ocQuaODdWTk3 9HySuqOR+SvxNzFmUgIYe6hkDLqaeUiIkGFcm+/65QR6r2SAOY1PmkUoUTxLUmB1P73X //q5xD7Q29oGv0xlG66ygVG8p1v5IX+rDpzbBXtQE+2gIcgdsxGElPy490u0Tvk/Uytv Zezn+bfhAf7S4orfveOsmCVGn61reiCRLgly0BHf4VXgVDy2LLQn6HKZL6oXTUZE7ZR+ GwR84xgWKHXGa20j0sNzcISNtnjPOIp48INJLScVuIN7nDg8978RWOzJEnxRdf/vrD/D NM+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=RSfpsA0Q70HozHrFTrC9rwszRbkG1c1eaqp/odjfo0M=; b=PjPzwgwPuNCFUzh0PMJL9mlVFsJKDWtYUNNFRtrBsiX1+5GHe9TFTsFLpxRzXYtKpv QK4yndvXP3QLP0I7Mca/kvpw5+CtytNPWNx52ERkzsKwzu/0WsG98QES28c708FkB5d8 hSlvhKZa2uSPnj1HJ968JvqdGOWmWmFSY+zR99FaCO8pPld8umkdHLZjoNYC/HPRpaO3 2MKQ+6YdgyZ2geydADTOEKHwrDCRoRGY9n6nTnndHlxZg9HX7nBR6XK1JBBfWVS0Xov2 /E/QaWEDHm+9WKxA7+7nDrNFo3Jl6LNkCZnEiQWNaZY6imwStr65kIHWZDhEum2mHamU LsQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=OfZxp75R; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k18-v6si2057691pgl.364.2018.09.12.13.10.31; Wed, 12 Sep 2018 13:10:46 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=OfZxp75R; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727844AbeIMBQW (ORCPT + 99 others); Wed, 12 Sep 2018 21:16:22 -0400 Received: from mail-it0-f66.google.com ([209.85.214.66]:39936 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726069AbeIMBQW (ORCPT ); Wed, 12 Sep 2018 21:16:22 -0400 Received: by mail-it0-f66.google.com with SMTP id h23-v6so4799854ita.5; Wed, 12 Sep 2018 13:10:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=RSfpsA0Q70HozHrFTrC9rwszRbkG1c1eaqp/odjfo0M=; b=OfZxp75RJqJf5apPkgjLi+RNUsrV7iUZV4atSpaKZT5XlDGPpUU+JkpZD8OZTxaGu4 pLrWkBaYGdlEWHQE+fFwLVbYbo1XYaXezZIaisFTzwUVgswPkQ0EAwdCG5Quo4+CAo93 8INRx24bVkB4823eOPoxelHAhL1n3grIvJxedLaHLOkN+tJDlxUSE3MJI315s/+CyhtG plsxYi+ICWLFVAA9uDLWDKPVtRaWG6Cl3zDfEds6e/HgA0FGF37EtxwsvOEpwk20x7hw HfySQnvg/ud1KIExiFD3+ILrYxM/lEBw4ksvSGQRzndzxdYPcEv9/Gd/W5QGhkNPHDiI uPEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=RSfpsA0Q70HozHrFTrC9rwszRbkG1c1eaqp/odjfo0M=; b=qlStJXY4M5LVT0iIl8a8WJxrofnFFfoTM4EPVxNc7YQtRxTCQPBspEjf7sDc2c9AKr fwjsMXnXiV2u86tZ2kbwr8MTMSbFq3CsExgCUHbQgivtAKPkfHDxXmfobEOnZm34uOBZ FC72YgnqNVkOTpKD2cdIsfZRNrMsFINrWP/gwaNdXiptS06U0djB3w4YBn7jh+IN21VD 0GlLlcoxVHA2cyXfB6+UYzUpbCYNizmprFmGOvIiQ0WS/PyFAhEBBclIJaK0+ogSjHE/ sO6erfgTwAL232SfqVysBsWj72E+tJklmeEEj9fLmUnspfDxS8HjnjXNqyPDXg9Aucsd z3Ig== X-Gm-Message-State: APzg51B/VDRQxR32NzUjoT8OIeGRMzn8T7OlIirCJifYGEf0OucE2n1K BghhrlxrGAgzFeeFmYjtiozfDAs86xtRdIBaI+i8KBkM X-Received: by 2002:a02:7123:: with SMTP id n35-v6mr3601905jac.91.1536783013348; Wed, 12 Sep 2018 13:10:13 -0700 (PDT) MIME-Version: 1.0 References: <20180911103403.38086-1-kirill.shutemov@linux.intel.com> In-Reply-To: <20180911103403.38086-1-kirill.shutemov@linux.intel.com> From: Vegard Nossum Date: Wed, 12 Sep 2018 22:10:00 +0200 Message-ID: Subject: Re: [PATCH] mm, thp: Fix mlocking THP page with migration enabled To: "Kirill A . Shutemov" Cc: Andrew Morton , Linux Memory Management List , LKML , stable , zi.yan@cs.rutgers.edu, Naoya Horiguchi , vbabka@suse.cz, aarcange@redhat.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 11 Sep 2018 at 12:34, Kirill A. Shutemov wrote: > > A transparent huge page is represented by a single entry on an LRU list. > 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: the > PMD on border of VM_LOCKED VMA will be split into PTE table. > > Introduction of THP migration breaks 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 PTE > 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 = 4; > void *addr; > > addr = 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 | MPOL_MF_MOVE_ALL); MPOL_MF_MOVE_ALL is actually not required to trigger the bug. > > return 0; > } > > Signed-off-by: Kirill A. Shutemov > Reported-by: Vegard Nossum Would you mind putting vegard.nossum@oracle.com instead? > Fixes: 616b8371539a ("mm: thp: enable thp migration in generic path") The commit I bisected the problem to was actually a different one: commit c8633798497ce894c22ab083eb884c8294c537b2 Author: Naoya Horiguchi Date: Fri Sep 8 16:11:08 2017 -0700 mm: mempolicy: mbind and migrate_pages support thp migration But maybe you had a good reason to choose the other one instead. They are close together in any case, so I guess it would be hard to find a kernel with one commit and not the other. > Cc: [v4.14+] > Cc: Zi Yan > Cc: Naoya Horiguchi > Cc: Vlastimil Babka > Cc: Andrea Arcangeli You could also add: Link: https://lkml.org/lkml/2018/8/30/464 Thanks for debugging this. Vegard