From patchwork Tue Nov 23 19:09:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shakeel Butt X-Patchwork-Id: 12635191 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E2B0C433F5 for ; Tue, 23 Nov 2021 19:09:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D87A16B0072; Tue, 23 Nov 2021 14:09:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D37306B0074; Tue, 23 Nov 2021 14:09:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BFEE36B0075; Tue, 23 Nov 2021 14:09:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0134.hostedemail.com [216.40.44.134]) by kanga.kvack.org (Postfix) with ESMTP id B0C116B0072 for ; Tue, 23 Nov 2021 14:09:33 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 70DA21828497C for ; Tue, 23 Nov 2021 19:09:23 +0000 (UTC) X-FDA: 78841133364.07.0ECB3D7 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf13.hostedemail.com (Postfix) with ESMTP id 12DCB1046312 for ; Tue, 23 Nov 2021 19:09:19 +0000 (UTC) Received: by mail-pl1-f201.google.com with SMTP id l14-20020a170903120e00b00143cc292bc3so9468949plh.1 for ; Tue, 23 Nov 2021 11:09:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=BLQhBkzThc5wElIUsHc2zAb2IUWmlXfCDG1CajkcIjg=; b=FDDqFo73a1z/W2nFOfqS+J/SlDpQ12TKK9oYaVG2VpIDfbJjzDPOSGqhH1Rm2lcVKH so4In/RnD8GFtcwlm9Dbz4Xqw5hHXEqGs66+/FVDYF2YZ1TwpdMANglTwiZ5bz43aFAo UhXTT6uKzDAZ+XbVsAnBDxX9eCFkbIeHY92PsE6e21VZNbBgv35aAk/Xa+1SlRjf6yUj fpqB9z/W+9e3tLx8SUvr09jaL+8D68+yfn7At6FAeiBaA1glen9k/DdCFte6JDz5X/sZ ShKrar4Omrb/4Sa6xdMWn5xdWIqWQbgURSiqhTQhjFH1cmVQ5sDelec/MPIbm9xVhTYd 43+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=BLQhBkzThc5wElIUsHc2zAb2IUWmlXfCDG1CajkcIjg=; b=lYZ0ZE7s6X1BlOlCNHScUT2kNy9zfVUEfA3bN3T4+XyeMiPcVDC9xkIQPVLsVvZFPA Uyy/AyLVZXo4mL15VCXCP9Kmz84KdWURtSGPU89zDMYwxHRvCJAk+d45tnxyZjueqN6h lcMgnzpGrBN1RzS7TieJgFELUcv6X+VWRgM3LlnLA0EW0KHleWoDGDpZKt490OSSiCNr GEkcN/MhRaY95uUjnDPTz1V4gUVjYI1QREsmvoBM6aufeHnOm7QdswjHCDRk9+uGC0xA eoMXIPDBHxIhadq9t0pLXtilESt9DAuHmi8UTzIK7wgI+8SIgn5WP/K/9pQODPkgVAWG ReIg== X-Gm-Message-State: AOAM5326eU65pSxfoLWMHUC2OkeqyGnAuc6YSB5FA4l0XFGzlwHoGWje U+trFWaEI5J2pY3xs19iTU1z25Pb80f0jA== X-Google-Smtp-Source: ABdhPJxfQZfH5raouxjz7FWh60DTXFFP8HIvwwCXC8VoU5lMMGWDaU9N83eIR4YH49T7pamZBG2cdjM2S1zzPQ== X-Received: from shakeelb.svl.corp.google.com ([2620:15c:2cd:202:bda6:1a8e:6bfd:ec0c]) (user=shakeelb job=sendgmr) by 2002:a63:82c7:: with SMTP id w190mr5449998pgd.117.1637694561581; Tue, 23 Nov 2021 11:09:21 -0800 (PST) Date: Tue, 23 Nov 2021 11:09:16 -0800 Message-Id: <20211123190916.1738458-1-shakeelb@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog Subject: [PATCH v2] mm: thp: update split_queue_len correctly From: Shakeel Butt To: David Hildenbrand , "Kirill A . Shutemov" , Yang Shi , Zi Yan , Matthew Wilcox Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Shakeel Butt X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 12DCB1046312 X-Stat-Signature: 7c1xub15nnmjjbgawa8obeftp8wq67a9 Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=FDDqFo73; spf=pass (imf13.hostedemail.com: domain of 3YTydYQgKCGISHAKEELBGOOGLE.COMLINUX-MMKVACK.ORG@flex--shakeelb.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3YTydYQgKCGISHAKEELBGOOGLE.COMLINUX-MMKVACK.ORG@flex--shakeelb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1637694559-629635 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: The deferred THPs are split on memory pressure through shrinker callback and splitting of THP during reclaim can fail for several reasons like unable to lock the THP, under writeback or unexpected number of pins on the THP. Such pages are put back on the deferred split list for consideration later. However kernel does not update the deferred queue size on putting back the pages whose split was failed. This patch fixes that. Without this patch the split_queue_len can underflow. Shrinker will always get that there are some THPs to split even if there are not and waste some cpu to scan the empty list. Fixes: 364c1eebe453 ("mm: thp: extract split_queue_* into a struct") Signed-off-by: Shakeel Butt Reviewed-by: Yang Shi --- Changes since v1: - updated commit message - incorporated Yang Shi's suggestion mm/huge_memory.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index e5483347291c..d393028681e2 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2809,7 +2809,7 @@ static unsigned long deferred_split_scan(struct shrinker *shrink, unsigned long flags; LIST_HEAD(list), *pos, *next; struct page *page; - int split = 0; + unsigned long split = 0; #ifdef CONFIG_MEMCG if (sc->memcg) @@ -2847,6 +2847,7 @@ static unsigned long deferred_split_scan(struct shrinker *shrink, spin_lock_irqsave(&ds_queue->split_queue_lock, flags); list_splice_tail(&list, &ds_queue->split_queue); + ds_queue->split_queue_len -= split; spin_unlock_irqrestore(&ds_queue->split_queue_lock, flags); /*