From patchwork Thu Feb 1 10:08:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 195211 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2719:b0:106:209c:c626 with SMTP id hl25csp23431dyb; Thu, 1 Feb 2024 01:16:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IFr8A639i3Y+t7RuCRRPqpT4TWx5gBMG5nbF+zbGJ+2BOYOdFIRkbXHwdFRQ3M4YEHu/9uf X-Received: by 2002:a05:6358:3121:b0:176:40fb:e123 with SMTP id c33-20020a056358312100b0017640fbe123mr4133182rwe.5.1706778972325; Thu, 01 Feb 2024 01:16:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706778972; cv=pass; d=google.com; s=arc-20160816; b=H1TXYVpG2S5aYVglarVES2zAuOCI6mjlHya3AM4x4FrZUOaKRQkN5YIw3ipbjmordF OpcfGnK0FQAvNNXYGDoES/hPvOn0VwjQFESLg5OjaswpZd3Zwv3LNCI7gjL7cGtPaF5G ZU6M9qhBevUQadPMFJuH62syMRgZBbGgQvC5n7iBcLTpWTLFMXathb4xlQ+fNjngpRVs PcIGOP2qpsCEcCCYJkHZjH45JyEe07MqkK173WENpYgq7u2/QbENveYTLXuUzadh+BmJ ChjUQ7/1TWxuofwrUVuD0AQrMsHnZI+1yz1EwpN8PjN9jA6SniHbRpvhgZpPYQ4DzMKq BdNg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=VLe+pmmDVDfQp16VtG7VOulZ/4B50muaiac6o0Il8VA=; fh=Eyyw3RZITiavMqjkGunQWXfcIECvYdlC6OH0Dx+5ZEw=; b=ETMEvUgVuRKhLjqOY5pL+g8ckDGs5FUQedKgeRmAxjDo/+0lyxdHyesfheYEf5bjBL yPPKQHiaw0cedg3w/empUZVcOOBKmMq2pNBAuV0av8Nf9nrtklH5w8N8noELiL2vbUoS eq8atELF3I8Yo96IBIbsofIPVPGGOKDtTb/lI+R1f53hlmB/LB1q82VOorG6MAJ4bCFd YJvu+oov020gY8nsC+IjfTA7Eq00mzpNt/idH/pvezKAxgb6ewxD6oxmWDr0i9elg/Kc TbASkVs+dTqO6OSF9fz03puNBKtTldkh+BID/Xu4MAvHfOELhh6ZsWW924s4OiOu5Y4i hPkw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-47836-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47836-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com X-Forwarded-Encrypted: i=1; AJvYcCUBjv8yfH6NqgO5CHNp6jXwcQ999Ro2+r9JvLpn5FG24qLYUyWW87M6KMWGnTmQye5DQ+6xNKb6irzFBjaRVu39Vc4WZA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id f38-20020a635566000000b005c1b30b1b65si11345483pgm.648.2024.02.01.01.16.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 01:16:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47836-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-47836-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47836-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 33BE028E5AC for ; Thu, 1 Feb 2024 09:14:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9B83015B991; Thu, 1 Feb 2024 09:13:21 +0000 (UTC) Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC69715B964; Thu, 1 Feb 2024 09:13:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.255 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706778800; cv=none; b=Npc6coOljiGRxmXGYRMySCci1lmvLszUCua64aqOtPBRd5Iu1HGwHFbGsOGacIjgEcF5+ETzBGribYvOzqphkcnmBfjStquwp8oSlcZC/4CTVtzpQRrk7oGuKU8UY7PXyiAufzNObAJn3UV2ni3cGoMLxt0BnyhmMJ78fbsiHrs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706778800; c=relaxed/simple; bh=cIwDUt+abyULJ5+fBvoBdeOcF9SxefKTziWM9T99Ad8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UTvkhZz0Q4P6t8dE69nM0V9si5CZc1iHPCVbWH4xlHdvlP1qPLr349OPAmox+unWGMVQWzO4pDzSRIiuFbXBc2spcu3XbT6EeAXn1Z/cMxivRMqBhaeG3ISp3T9+v2Xle/W5c0eklXtl072tU5h13eF1Y3R1tCAAYL1FPaX/HJY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.255 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4TQY7c3fSJz1Q8hG; Thu, 1 Feb 2024 17:11:56 +0800 (CST) Received: from dggpemd200004.china.huawei.com (unknown [7.185.36.141]) by mail.maildlp.com (Postfix) with ESMTPS id 971BA1401E0; Thu, 1 Feb 2024 17:13:09 +0800 (CST) Received: from huawei.com (10.175.113.32) by dggpemd200004.china.huawei.com (7.185.36.141) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.28; Thu, 1 Feb 2024 17:13:09 +0800 From: Liu Shixin To: Alexander Viro , Christian Brauner , Jan Kara , Matthew Wilcox , Andrew Morton CC: , , , Liu Shixin Subject: [PATCH 1/2] mm/readahead: stop readahead loop if memcg charge fails Date: Thu, 1 Feb 2024 18:08:34 +0800 Message-ID: <20240201100835.1626685-2-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240201100835.1626685-1-liushixin2@huawei.com> References: <20240201100835.1626685-1-liushixin2@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemd200004.china.huawei.com (7.185.36.141) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789687467530166796 X-GMAIL-MSGID: 1789687467530166796 When a task in memcg readaheads file pages, page_cache_ra_unbounded() will try to readahead nr_to_read pages. Even if the new allocated page fails to charge, page_cache_ra_unbounded() still tries to readahead next page. This leads to too much memory reclaim. Stop readahead if mem_cgroup_charge() fails, i.e. add_to_page_cache_lru() returns -ENOMEM. Signed-off-by: Liu Shixin Signed-off-by: Jinjiang Tu Reviewed-by: Jan Kara --- mm/readahead.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mm/readahead.c b/mm/readahead.c index 23620c57c1225..cc4abb67eb223 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -228,6 +228,7 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, */ for (i = 0; i < nr_to_read; i++) { struct folio *folio = xa_load(&mapping->i_pages, index + i); + int ret; if (folio && !xa_is_value(folio)) { /* @@ -247,9 +248,12 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, folio = filemap_alloc_folio(gfp_mask, 0); if (!folio) break; - if (filemap_add_folio(mapping, folio, index + i, - gfp_mask) < 0) { + + ret = filemap_add_folio(mapping, folio, index + i, gfp_mask); + if (ret < 0) { folio_put(folio); + if (ret == -ENOMEM) + break; read_pages(ractl); ractl->_index++; i = ractl->_index + ractl->_nr_pages - index - 1;