From patchwork Tue Dec 11 14:29:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 10723905 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 5E3191869 for ; Tue, 11 Dec 2018 14:30:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E4142B192 for ; Tue, 11 Dec 2018 14:30:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 42BC32B1AA; Tue, 11 Dec 2018 14:30:16 +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 C17DF2B1A8 for ; Tue, 11 Dec 2018 14:30:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 858308E0094; 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 7A2788E0096; 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 3EB3D8E0094; 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-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by kanga.kvack.org (Postfix) with ESMTP id D99E68E0095 for ; Tue, 11 Dec 2018 09:30:09 -0500 (EST) Received: by mail-ed1-f69.google.com with SMTP id o21so7040297edq.4 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=qndwCSP65fzZEEikWfQfaFyR1QRf8lbn9R8lxbp3TrI=; b=bqTcDwUot9gaFK7gvOOJmZXIoP8k3X31Ts2Ym2hVd3zgjWAZcE0CSF0FZW626rmEfg J4aUXWJ86YNljblgcukSvzDj+k64oRZ5Pu3PXX3QJfN4mg0O71O+x4YcqousUMPW69S9 DfB8ZVIS8Jrj3lhkHOgWxJQTqJc4z7D7YCrtsx8eX7QtLAcswqEpgzJ7Spnt9Yo+a0dF M3dvUUQSaeZY1fbMBr3AgiQ3O7EBi+SazaJH9F79uzLvrPpOccZtI/Fo6vqEHLQrdCiA uJPMFvGAP70nYB2cwaRy1VtUdQ+nx12cDvjIhowHnm0VKyDi9Riult7pluki3Y+f95MD aHmg== 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+aEWaaaCsljdTSKmtCuCap9cfN5ylC4cK5Sz7/g2QInxFOUsYY8+Bf H5RpB6jcrNXZanh8WyL/Iplx8FIrdizsLq6TmarE5BmpGSu/0C7JKIsyiVHeIEtC09GWcXVVX1A Gr6bFyae7TlcZRk5UR/bfeaX6sWtm0BFRTx6GABSC3FTrLRu9fLCmi14Svam17dCn6g== X-Received: by 2002:a50:da43:: with SMTP id a3mr15752675edk.62.1544538609368; Tue, 11 Dec 2018 06:30:09 -0800 (PST) X-Google-Smtp-Source: AFSGD/XWpKIyQT2VS4WVjPXRTpNARwuTYASOY2fMVvb1vkCJalC0jpnO0UXYnP+eY0uI98j41C+8 X-Received: by 2002:a50:da43:: with SMTP id a3mr15752612edk.62.1544538608355; 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=AKpvAfnm1UBYgIs6iUgDPMvFFQWTsTtB9flU2KjpZqRzACv58pv4ln0OLLfqeqTwNt GTQhJ3Ca8rb3YfVC6WNim222HHcf4EM3gBPnTHIFVq0KPW4VHmNR6fGX4ZrEyla3gl9b XbG2T0P/rn/PY/X6ozfeC0hHGJF4f2u1JlCfsJntgOWWKZZnJPP1TBBeB6bSIe4pQU/q /PDVhmaQb40d+7ofZiv2YFWhxnfxnF69PtyPYF3G+cpoM8dEoAy68ZIHJurua5l1AFrT DtlqBagDb7ZPDlfp1Ib3I+iTqE5hTPKsfPEL8C8G9wVG8yWbsePwqZHa7RHxXGWrw2WP XHjw== 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=qndwCSP65fzZEEikWfQfaFyR1QRf8lbn9R8lxbp3TrI=; b=BuqrFZUWfrIGPKXJLts50fwHybOGtyNbhOvPQqq4PeLn7U3fUl1W4ofCSZUDDgmz8B n2gBP1oi0RbvW+OwTCS7g231VHt023X8K+LhLIXOgr8Woo1wqDdAYvSzE0kbZw2BSu2L ekGU5ZYw+4gj0ptkItDGaFlH/wCGv7giYy6Tt5ncL/nYQS9sdihgbWlhm6g+JXfuPO2J mxLTSNH8wlmCf+9cZAlqHd2B/VZR4YcBy7hHMPSOFKGuN/f0rTpx6k5cgMiLntTz9Hfz SF/ZmyqiMaIV9TxGz9tshdTJkfLOItgEyXpuCZCZKN7H/6wQuQJ+yA2IBXXicZXUftBQ kfsg== 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 q19-v6si1846770ejt.57.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 relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id B5A98B039; 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 2/3] mm, page_alloc: reclaim for __GFP_NORETRY costly requests only when compaction was skipped Date: Tue, 11 Dec 2018 15:29:40 +0100 Message-Id: <20181211142941.20500-3-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 For costly __GFP_NORETRY allocations (including THP's) we first do an initial compaction attempt and if that fails, we proceed with reclaim and another round of compaction, unless compaction was deferred due to earlier multiple failures. Andrea proposed [1] that we count all compaction failures as the defered case in try_to_compact_pages(), but I don't think that's a good idea in general. Instead, change the __GFP_NORETRY specific condition so that it only proceeds with further reclaim/compaction when the initial compaction attempt was skipped due to lack of free base pages. Note that the original condition probably never worked properly for THP's, because compaction can only become deferred after a sync compaction failure, and THP's only perform async compaction, except khugepaged, which is infrequent, or madvised faults (until the previous patch restored __GFP_NORETRY for those) which are not the default case. Deferring due to async compaction failures should be however also beneficial and thus introduced in the next patch. Also note that due to how try_to_compact_pages() constructs its return value from compaction attempts across the whole zonelist, returning COMPACT_SKIPPED means that compaction was skipped for *all* attempted zones/nodes, which means all zones/nodes are low on memory at the same moment. This is probably rare, which would mean that the resulting 'goto nopage' would be very common, just because e.g. a single zone had enough memory and compaction failed there, while the rest of nodes could succeed after reclaim. However, since THP faults use __GFP_THISNODE, compaction is also attempted only for a single node, so in practice there should be no significant loss of information when constructing the return value, nor bias towards 'goto nopage' for THP faults. [1] https://lkml.kernel.org/r/20181206005425.GB21159@redhat.com Suggested-by: Andrea Arcangeli Signed-off-by: Vlastimil Babka Cc: Andrea Arcangeli Cc: David Rientjes Cc: Mel Gorman Cc: Michal Hocko --- mm/page_alloc.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 2ec9cc407216..3d83a6093ada 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4129,14 +4129,14 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, */ if (costly_order && (gfp_mask & __GFP_NORETRY)) { /* - * If compaction is deferred for high-order allocations, - * it is because sync compaction recently failed. If - * this is the case and the caller requested a THP - * allocation, we do not want to heavily disrupt the - * system, so we fail the allocation instead of entering - * direct reclaim. + * If compaction was skipped because of insufficient + * free pages, proceed with reclaim and another + * compaction attempt. If it failed for other reasons or + * was deferred, do not reclaim and retry, as we do not + * want to heavily disrupt the system for a costly + * __GFP_NORETRY allocation such as THP. */ - if (compact_result == COMPACT_DEFERRED) + if (compact_result != COMPACT_SKIPPED) goto nopage; /*