Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp831500lqb; Wed, 17 Apr 2024 12:00:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV7EcST7V4liVNnRKwnwpPUZOXoEd0EDkWwuGI7DPWIZEvGW5Tcwerl5ZA9UM7pmdbaD1Bfoki036Hw6P1q8+R/M04Wb3MsVQ0BkPFZwg== X-Google-Smtp-Source: AGHT+IFDKgqgXR8v1WIQEad9zO6y0WjwtencNhxT/EKLHaZS5ct8eykYOwZiuZUIMWRl7YtVqGjz X-Received: by 2002:a17:90a:f3ca:b0:2a7:44c8:3e4d with SMTP id ha10-20020a17090af3ca00b002a744c83e4dmr294282pjb.2.1713380447302; Wed, 17 Apr 2024 12:00:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713380447; cv=pass; d=google.com; s=arc-20160816; b=MUI8eH5JLIDRKrgeMrOjrSR3YvFPA7qy8ChUJ08s6YHa/+pocHyqVIVyv8P0OUhS0K Jomd4ovBj3nQaqlpLBN/tNnIbt6zfKAS108E0LQvfMe2q8kD7ZmmSo/j/th1z1jF/GGq f2sagLODggoVkbvshzsIhUWrUXtn3GQinlKf0WloFnnHPzVjv0NL0qgMg5jhTtZ5UE8j lFbQgdmpqUGLCxtP4kU5qdIzNQtNdiBhRSZ42Nu1EZB9/M4Dr3xSI4z0/b+eU6WqXDoH udXUNkV4wPOjUtAlD8tHTSy7Ckkt4uY8W1RmsE6qsU+sk50R9oRrck7CcnvCgDVWrQr0 /D2A== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=9v67SsM86RHd+fq1rQ349Md4AubcsHfvAyQsA3MVFJM=; fh=1wdCfTVdwY462Ok0fY2CPyE/oveGB8oLCgYxv9n0rOE=; b=mWsOUDLgFG+aV/n9kG0glH02hXQrpUPSEgDZ4gP+i4U/kE8NE/4ya4rh108MWjjt5m e82ineEcAYu41oAvJXfWw6dlpSf5bqDecM0zdy/iDRrocFIbWSyyE8HyehIvAHsDeqUd TkKhWrd4ON8rLWNDxhWXISnu1TpxTZuFNIIckRWpts/wSyHjffcerIElfjUVr3NnoscC AatCCABLeLYZ0EtfJJgXSVrlzDv3iksjCOgLLc7TcfnT7SXJaC+Ago8jhNYP5Kq/6emO fGQ2LKZAezcwNrXI8ZNX30sdtSBtYqdwQTnBmd3vmG/sepBXqR4Hv/foY1Mw3md48f5H 16FQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-11-20 header.b="mI0r/4up"; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel+bounces-149096-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-149096-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=oracle.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id u10-20020a17090ae00a00b002a290022891si1678941pjy.162.2024.04.17.12.00.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 12:00:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-149096-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-11-20 header.b="mI0r/4up"; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel+bounces-149096-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-149096-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=oracle.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 EE04F281EE7 for ; Wed, 17 Apr 2024 19:00:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9D9B038F9B; Wed, 17 Apr 2024 19:00:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="mI0r/4up" Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (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 3A856383AC for ; Wed, 17 Apr 2024 19:00:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.165.32 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713380403; cv=none; b=Lni3EaMGzFpqkbGCTfnbp2nqDQnsnlTks2ENptaisZtP33wXZtQyVuzgyJaLIKChEFN6DTSOxGh5+SsWPwhsZswFItl/twNrWjIIXOCsPKRPXO2najW7UzeMMztan6QGuUE8byWHc4ReTkJAi6RdGbSZjCe/+q8TpdmBHnZTT/U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713380403; c=relaxed/simple; bh=tuV+qPoXQpGm4H3YRj7CO/TxtGIzN2KTYn38mOU54hA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=AvXXLVYVw30wlnSf+L18MmawYX9GUjqwbqmSuC+y+Igi5fXif252MESWpBbWvezKWodXG2GRpW7zRX8n3TJSQ0Jn6w6n0XteAlZAA3OOOeMFkJrGZ6VgEFGGCP8r+a1X+9DBp9ryn7454X56TvPVl3H4FbJs/paDZdqGEAGsEmA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=mI0r/4up; arc=none smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43HHiM9Y005952; Wed, 17 Apr 2024 18:59:50 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=corp-2023-11-20; bh=9v67SsM86RHd+fq1rQ349Md4AubcsHfvAyQsA3MVFJM=; b=mI0r/4up/xr2QNH8dwUyZLCnu1R4MSJh0AJkbntUZCyCbfBojepeT/Zf+snMF1aHjOze F/ilLS91wus6BeNIstW/DWGkt9tI6a+u5Xvj1z0faMQyVznEqH9oAfeWT+4mgUczC3d8 68H0Cm521xUDy7Q0GKID0TBPqaaeT7A4DdLQJlQKlk+zAUdnb7d9KMO33k47aN8CIflI lPL8XPzFn/kibEDUL5J9V/m4GFeJoIyR4Kc0RMSWDuaEQNa7Y6JWlbJiHZRZKxkmwKL4 J8x/2B0uo43PcksMl63/F5S5QJYgL/cTuCzi8cl1Q7YKTjSBv89plNap6IblYvk1K5HJ ew== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xfhxbrjx6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Apr 2024 18:59:48 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43HIZmGN012528; Wed, 17 Apr 2024 18:59:40 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xgkwhbxj3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Apr 2024 18:59:40 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 43HIxdmp026239; Wed, 17 Apr 2024 18:59:39 GMT Received: from jfwang-mac.us.oracle.com (dhcp-10-65-140-165.vpn.oracle.com [10.65.140.165]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3xgkwhbxhc-1; Wed, 17 Apr 2024 18:59:39 +0000 From: Jianfeng Wang To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: akpm@linux-foundation.org, cl@linux.com, vbabka@suse.cz, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, junxiao.bi@oracle.com Subject: [PATCH v2 0/1] slub: limit number of slabs to scan in count_partial() Date: Wed, 17 Apr 2024 11:59:37 -0700 Message-ID: <20240417185938.5237-1-jianfeng.w.wang@oracle.com> X-Mailer: git-send-email 2.42.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-17_16,2024-04-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 phishscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404170136 X-Proofpoint-ORIG-GUID: OGG2cmFhFCqRvHMNTfKVATP0M2zuI7z7 X-Proofpoint-GUID: OGG2cmFhFCqRvHMNTfKVATP0M2zuI7z7 This patch fixes a known issue in get_slabinfo() which relies on count_partial() to get the exact count of free objects in a kmem_cache_node's partial list. For some slub caches, their per-node partial list can be extremely long. The current version of count_partial() traverses the partial list to get the exact count of objects while holding the kmem_cache_node's spinlock. This process may take a long time, during which slab allocations are blocked and IRQs are disabled. In production workloads, even NMI watchdog can be triggered due to this matter. Moreover, getting the exact count of objects may not be useful as well: the count may change right after the spinlock is released and re-captured by others. The proposed fix is to limit the number of slabs to scan, and output an approximated object count for a long partial list. The v1 patch counts N slabs from the list's head and then uses it to approximate the total object count in the list. As suggested by Vlastimil, an alternative method, i.e., counting N/2 from both the list's head and tail, produces a more accurate approximation after the partial list is sorted by kmem_cache_shrink(). --- Changes since v1 [1] - Update the approximation method by counting from the list's head and tail - Cap the approximation by the total object count - Update the commit message to add benchmark results and explain the choice [1] https://lore.kernel.org/linux-mm/20240411164023.99368-1-jianfeng.w.wang@oracle.com/ Thanks, --Jianfeng Jianfeng Wang (1): slub: limit number of slabs to scan in count_partial() mm/slub.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) -- 2.42.1