From patchwork Tue Dec 11 14:29:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 10723901 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B51DE91E for ; Tue, 11 Dec 2018 14:30:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A56C32B199 for ; Tue, 11 Dec 2018 14:30:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9A2A52B1A5; Tue, 11 Dec 2018 14:30:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 006EC2B19A for ; Tue, 11 Dec 2018 14:30:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 290CB8E0097; Tue, 11 Dec 2018 09:30:10 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 240428E004D; Tue, 11 Dec 2018 09:30:10 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 12E5F8E0097; Tue, 11 Dec 2018 09:30:10 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by kanga.kvack.org (Postfix) with ESMTP id AC8998E004D for ; Tue, 11 Dec 2018 09:30:09 -0500 (EST) Received: by mail-ed1-f70.google.com with SMTP id w15so7010261edl.21 for ; Tue, 11 Dec 2018 06:30:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=TPy8IMX//uqJOrVHEIcG76wWCF/8Rr43ZW6+UNT8RBU=; b=V+TEho+NB5BLW0SJHKwpuI2s+iISkL7lnU1FSP/xUKUkPshzEB1DhuQJZPf730NkRw I6DRy9syp2lpFB5FrHhNO5VPVt2OlxT+vD1bmzlc8BC27i7K6c6+WaTvtZgZm5BZMJq6 BS4dgdpZzf6FGWRxLZ/u0sF4Ihzl8HEIahfcOpLO6WTi0ER4GGnOclVC0ldE01UjiF5e J7s2hPMrNoXH91FmvU7bvg9bHS1g9/dsH/jsEmyVgT+5XpDXKOUNEwHdbJqCLWOhpd45 omSBD2w2q7XQDaj367lfCaay9fVnNqqAhn2z6390/I5sh8Dy5llDrFgBG8WKGB4T0lhe OEwg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of vbabka@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-Gm-Message-State: AA+aEWbXKt/8K5N4oKRpL6oxDsBv2iCKHbSODWhswzM4SzlN0xneFBPf fIhCCFUH56vZiARWIHtgwGwJz8v4H7zixo2p2Mt0gT1PainJG7HsLdmP7fpm4IOWCH6L6lIRuMJ o8KaiHRR+7fBaxLy/up855IC3uMCMSsejWpRZ+MUyQrQPAwhOi/SoGEAXJacjEbHu0g== X-Received: by 2002:a50:ea8d:: with SMTP id d13mr15247010edo.126.1544538609209; Tue, 11 Dec 2018 06:30:09 -0800 (PST) X-Google-Smtp-Source: AFSGD/WexnIySDKWkczFici3eDl/cwgvZN7ZT5U3pF0xBikUnim3H9LY/+pGVKxJa3u5CL36XTAu X-Received: by 2002:a50:ea8d:: with SMTP id d13mr15246952edo.126.1544538608265; Tue, 11 Dec 2018 06:30:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544538608; cv=none; d=google.com; s=arc-20160816; b=vH03McHTTsOLpR5Mygd1ei3fFkDZhkXVdRIhvMJhR0ccavZ/0q4lLIFVo/05XoRJWP ruJ3o+J35pvJtKFr/Jvw+LElkOgxNTnJw4J0aCPHeLrpucFJikrfLms6uA5QanlPB7Z1 4IZOLqPh0omKgdbcmbEDX2ghBqr9Rsr4Q+cV8GMoq3iqLW+p6TgYmGtn5mKUeA/tEN6h BWApWqrXO1GaIepFQ6eRwdKyv+QDGQsjc/t9RfVazSvL7LIuSjjma9nRccrcCsdf5FNz TcrjjOCbUy0xggHu8X50r9MzEF1bblLiJx4LAsyhtGSiRQAVDv6A8paogjIEfe1WEb5C s1lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=TPy8IMX//uqJOrVHEIcG76wWCF/8Rr43ZW6+UNT8RBU=; b=Qj4z/uonGuS4r1XnAx4NCiPjya5SvbCqSqR/rhtWXrE2l7F8bGOM+TciCRRxrvD+ex R7Lrf5NHukL/kJ91NDdHBnzYjLiXy+96oiJa1zfvHDtNXRNAicreGswzdaTXUSBGyoXd IwXCqXD9OyLjBXav17VWszO5auDgsUUzu0Z/luBLQNc0Rv45IDLjZBsLaR988ct6Ltp9 AIqlDZZ/MO9Q9iYg++bVx2ElsgpLX4xG6GAT8s46XDnJvW0BQXzGw14JwExQKlR6t0KP XpPauFHGLzH6lrZwjZ2vj7BkVage9WvFJ+Y/XJK56s6LO8CKngoFK1pRGRpvwjCwm1iM GuIQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of vbabka@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=vbabka@suse.cz Received: from mx1.suse.de (mx2.suse.de. [195.135.220.15]) by mx.google.com with ESMTPS id k21-v6si805323ejp.31.2018.12.11.06.30.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Dec 2018 06:30:08 -0800 (PST) Received-SPF: pass (google.com: domain of vbabka@suse.cz designates 195.135.220.15 as permitted sender) client-ip=195.135.220.15; Authentication-Results: mx.google.com; spf=pass (google.com: domain of vbabka@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id B62E8B03A; Tue, 11 Dec 2018 14:30:07 +0000 (UTC) From: Vlastimil Babka To: David Rientjes , Andrea Arcangeli , Mel Gorman Cc: Michal Hocko , Linus Torvalds , linux-mm@kvack.org, Andrew Morton , Vlastimil Babka Subject: [RFC 1/3] mm, thp: restore __GFP_NORETRY for madvised thp fault allocations Date: Tue, 11 Dec 2018 15:29:39 +0100 Message-Id: <20181211142941.20500-2-vbabka@suse.cz> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181211142941.20500-1-vbabka@suse.cz> References: <20181211142941.20500-1-vbabka@suse.cz> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Commit 2516035499b9 ("mm, thp: remove __GFP_NORETRY from khugepaged and madvised allocations") intended to make THP faults in MADV_HUGEPAGE areas more successful for processes that indicate that they are willing to pay a higher initial setup cost for long-term THP benefits. In the current page allocator implementation this means that the allocations will try to use reclaim and the more costly sync compaction mode, in case the initial direct async compaction fails. However, THP faults also include __GFP_THISNODE, which, combined with direct reclaim, can result in a node-reclaim-like local node thrashing behavior, as reported by Andrea [1]. While this patch is not a full fix, the first step is to restore __GFP_NORETRY for madvised THP faults. The expected downside are potentially worse THP fault success rates for the madvised areas, which will have to then rely more on khugepaged. For khugepaged, __GFP_NORETRY is not restored, as its activity should be limited enough by sleeping to cause noticeable thrashing. Note that alloc_new_node_page() and new_page() is probably another candidate as they handle the migrate_pages(2), resp. mbind(2) syscall, which can thus allow unprivileged node-reclaim-like behavior. The patch also updates the comments in alloc_hugepage_direct_gfpmask() because elsewhere compaction during page fault is called direct compaction, and 'synchronous' refers to the migration mode, which is not used for THP faults. [1] https://lkml.kernel.org/m/20180820032204.9591-1-aarcange@redhat.com Reported-by: Andrea Arcangeli Signed-off-by: Vlastimil Babka Cc: Andrea Arcangeli Cc: David Rientjes Cc: Mel Gorman Cc: Michal Hocko --- mm/huge_memory.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 5da55b38b1b7..c442b12b060c 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -633,24 +633,23 @@ static inline gfp_t alloc_hugepage_direct_gfpmask(struct vm_area_struct *vma) { const bool vma_madvised = !!(vma->vm_flags & VM_HUGEPAGE); - /* Always do synchronous compaction */ + /* Always try direct compaction */ if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_DIRECT_FLAG, &transparent_hugepage_flags)) - return GFP_TRANSHUGE | (vma_madvised ? 0 : __GFP_NORETRY); + return GFP_TRANSHUGE | __GFP_NORETRY; /* Kick kcompactd and fail quickly */ if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_FLAG, &transparent_hugepage_flags)) return GFP_TRANSHUGE_LIGHT | __GFP_KSWAPD_RECLAIM; - /* Synchronous compaction if madvised, otherwise kick kcompactd */ + /* Direct compaction if madvised, otherwise kick kcompactd */ if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_OR_MADV_FLAG, &transparent_hugepage_flags)) return GFP_TRANSHUGE_LIGHT | - (vma_madvised ? __GFP_DIRECT_RECLAIM : + (vma_madvised ? (__GFP_DIRECT_RECLAIM | __GFP_NORETRY): __GFP_KSWAPD_RECLAIM); - /* Only do synchronous compaction if madvised */ + /* Only do direct compaction if madvised */ if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG, &transparent_hugepage_flags)) - return GFP_TRANSHUGE_LIGHT | - (vma_madvised ? __GFP_DIRECT_RECLAIM : 0); + return vma_madvised ? (GFP_TRANSHUGE | __GFP_NORETRY) : GFP_TRANSHUGE_LIGHT; return GFP_TRANSHUGE_LIGHT; }