Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3974476pxk; Tue, 8 Sep 2020 07:34:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJws/KPrdCGd3A9WH9BbJRJW9UNnkuh5tEdH1sft2CDN1voWEn7aa0sx8MgXVXkLRdzG/wwy X-Received: by 2002:a50:cf0b:: with SMTP id c11mr11360130edk.87.1599575679160; Tue, 08 Sep 2020 07:34:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599575679; cv=none; d=google.com; s=arc-20160816; b=x1wLaUnWdfA1Cng7dC0thXqMuLX9KLOAaFjF/ti3XYaRqiFt5bpIJwJJXEj2bCJku1 jqcPX9Qk6sS3szJeS/OtBsXyBGqnmeC+v6fTrOPIOwCnFQnZEXWI94UB+fxmfr/db1JV kk9VKS9qrindJcosob/+Z6OtfLASrMkrixs7Xtlj6iIxPDlOPdRt3NRWzcxPBurkGmuK CO2JC86Gr00qDUalVfskPx49omYIWBUkW8fol4NUOlTK3DHn+4pdXpTBZ3zKs95nhvU6 YGHVVD63sHGLVsAIe1FmBPT0WhfnghCnfCEm1eClDJqcnu1yjA8rhQRi+cMOyqV3/zOV dCRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=qbyfb7IENIIZnzycuSlXwlchWqptmqZvtFIJsiTST2Q=; b=TAOOwYBJxHwBJ1VugVvjycpqfles8CK+FdxVOGKloeiU+3VownvHCyj67kWenRQ9y2 aEcikATQ9Yv1ejL+f55AfX3diLnBEcWZdLkhajU0Qbm98KazVP50IJlhJP0BugfowM5F SMiBKsv37stVz07ok899Lyn1NBSaZ2dMFA9eordjvbY+c1LUGwZ74cU+AzJlpUAegX3d 6NAN/7AcRhbgrQF2Z7Ea2ZgfWFFDeuTk4znSz3KiA0LGYBC0d2U970p+ddAP1t6P2766 1voBh/8qSHwSHmddVMz5NZGBVvUImUu4GMzs7hDcgfX+6cGTSFHFYfuMAOJCLKvhZlGy jT9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=TcMeF22U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g13si11448025ejw.573.2020.09.08.07.34.14; Tue, 08 Sep 2020 07:34:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=TcMeF22U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729337AbgIHOba (ORCPT + 99 others); Tue, 8 Sep 2020 10:31:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729719AbgIHO0E (ORCPT ); Tue, 8 Sep 2020 10:26:04 -0400 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22BA0C08E818 for ; Tue, 8 Sep 2020 07:25:10 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id j34so4760616pgi.7 for ; Tue, 08 Sep 2020 07:25:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=qbyfb7IENIIZnzycuSlXwlchWqptmqZvtFIJsiTST2Q=; b=TcMeF22UNZIEg9d0gzz98TwFeIxyqfPvLagxomEInN8Jz1RMp7VDdtXA6EehKzjSG8 /5SlRkTXBSFEzI7pP7AjUsnj7qEH/1FwaqMYorliQ5tbjGHarxMvO8K2yyl3kx+Odxn2 3p+pVF9186L5mOvCvvk4+cuQxqF1uHjnnMNSMl/4X7ONNFqdgPB5cc4Rdoy/RJMqBX7L bEIWU1IN9uRC1oJ6e3XY9xep4JvDEaHn65KJdAK/LLiIaIQAFmKTXm5LoKEfec4Q8zPo Af1hYqV97gBqQ2vTs0XQpUYzWpFqhNlJegb6cSioxGUw8S/cvolkKosVgz5eZAOnnSmN NcTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=qbyfb7IENIIZnzycuSlXwlchWqptmqZvtFIJsiTST2Q=; b=VhKgYKcrWlRgwFv7THtlgALXJHdamqslide4B7eVDKyzPpi88cPYg0308F7zIzjJSN FqM2XJ29IKD8WRYRdTj9jV5WZUr7tE2BtJaF5lJihUaMohmhP0jR2faJzXgvgSVYPRYN zyI8H1awCwD6jlYtayNWhBHvTM3XSo6yOTECmZt6y4Jxdnmk3zb3u5alFh6fMSt4jRaI bnaKT0Det1E4BSLg+ymcSLvi+pbRPZnZR5KCCkHuQWBQzXwGHlNd5Ic5uQXWG8hJI4vd mg22laKx2LXIdy4N2Wg8SBfjvJ2PJVtUPW6RmyHiQj5LgJPER2u2KUreIn6/9zXsXRhQ hCYA== X-Gm-Message-State: AOAM531RYn9caQfqIAh9t+ukWnJ5hz+4foxwRz1OR9IaxekpfJXv/ZWi xyMg/k2hAf6uzkJBkx3YD4oROmnzLvagf9HH X-Received: by 2002:aa7:8e85:: with SMTP id a5mr23961248pfr.96.1599575109593; Tue, 08 Sep 2020 07:25:09 -0700 (PDT) Received: from localhost.localdomain ([103.136.220.67]) by smtp.gmail.com with ESMTPSA id v26sm6120436pgo.83.2020.09.08.07.25.06 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Sep 2020 07:25:08 -0700 (PDT) From: zangchunxin@bytedance.com To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Chunxin Zang , Muchun Song Subject: [PATCH] mm/vmscan: fix infinite loop in drop_slab_node Date: Tue, 8 Sep 2020 22:24:56 +0800 Message-Id: <20200908142456.89626-1-zangchunxin@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chunxin Zang On our server, there are about 10k memcg in one machine. They use memory very frequently. When I tigger drop caches,the process will infinite loop in drop_slab_node. There are two reasons: 1.We have too many memcgs, even though one object freed in one memcg, the sum of object is bigger than 10. 2.We spend a lot of time in traverse memcg once. So, the memcg who traversed at the first have been freed many objects. Traverse memcg next time, the freed count bigger than 10 again. We can get the following info through 'ps': root:~# ps -aux | grep drop root 357956 ... R Aug25 21119854:55 echo 3 > /proc/sys/vm/drop_caches root 1771385 ... R Aug16 21146421:17 echo 3 > /proc/sys/vm/drop_caches root 1986319 ... R 18:56 117:27 echo 3 > /proc/sys/vm/drop_caches root 2002148 ... R Aug24 5720:39 echo 3 > /proc/sys/vm/drop_caches root 2564666 ... R 18:59 113:58 echo 3 > /proc/sys/vm/drop_caches root 2639347 ... R Sep03 2383:39 echo 3 > /proc/sys/vm/drop_caches root 3904747 ... R 03:35 993:31 echo 3 > /proc/sys/vm/drop_caches root 4016780 ... R Aug21 7882:18 echo 3 > /proc/sys/vm/drop_caches Use bpftrace follow 'freed' value in drop_slab_node: root:~# bpftrace -e 'kprobe:drop_slab_node+70 {@ret=hist(reg("bp")); }' Attaching 1 probe... ^B^C @ret: [64, 128) 1 | | [128, 256) 28 | | [256, 512) 107 |@ | [512, 1K) 298 |@@@ | [1K, 2K) 613 |@@@@@@@ | [2K, 4K) 4435 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@| [4K, 8K) 442 |@@@@@ | [8K, 16K) 299 |@@@ | [16K, 32K) 100 |@ | [32K, 64K) 139 |@ | [64K, 128K) 56 | | [128K, 256K) 26 | | [256K, 512K) 2 | | In one drop caches action, only traverse memcg once maybe is better. If user need more memory, they can do drop caches again. Signed-off-by: Chunxin Zang Signed-off-by: Muchun Song --- mm/vmscan.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index b6d84326bdf2..9d8ee2ae5824 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -699,17 +699,12 @@ static unsigned long shrink_slab(gfp_t gfp_mask, int nid, void drop_slab_node(int nid) { - unsigned long freed; + struct mem_cgroup *memcg = NULL; + memcg = mem_cgroup_iter(NULL, NULL, NULL); do { - struct mem_cgroup *memcg = NULL; - - freed = 0; - memcg = mem_cgroup_iter(NULL, NULL, NULL); - do { - freed += shrink_slab(GFP_KERNEL, nid, memcg, 0); - } while ((memcg = mem_cgroup_iter(NULL, memcg, NULL)) != NULL); - } while (freed > 10); + shrink_slab(GFP_KERNEL, nid, memcg, 0); + } while ((memcg = mem_cgroup_iter(NULL, memcg, NULL)) != NULL); } void drop_slab(void) -- 2.11.0