Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp759576rdb; Thu, 18 Jan 2024 19:53:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IGQ273lyubb7V7UREm/PBr7bnKSlFd6zk/V/ekFFUEXY5EYYWTX9qK2ugdonWg7sbC067IA X-Received: by 2002:a9d:748b:0:b0:6e0:b1ee:d993 with SMTP id t11-20020a9d748b000000b006e0b1eed993mr2066177otk.21.1705636410346; Thu, 18 Jan 2024 19:53:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705636410; cv=pass; d=google.com; s=arc-20160816; b=llPNApRGpHrKxsNb924KL2kKCNheeKijJ9mh81Gl7pq9BBti8Wr/7OF5LVFOPVsJub Y7QD40C6vOEJcWBccZ1oPIqZTQvCGXo65LmLMbEeKLFaK14H8hPRJmnUI/RjkALZiePf 3tA2BmD/3IXpZbz+RVCKIqKhb7yqEqy6HqJnLSVyVmIso66qLKc0wfyQU6z1/GcaByB4 eKj2tScXfHRKEf5ZnmlN/vuqViW6aOV9b9zg0K+Y1Pkt5RZEVd1wwCcXoxkJ4juQZ1W/ JqbCzJlcXT2uIDennarh9KPDd+46KU2x2zQagJOBIlhAnBu9GvU3NSDBCm5hKF7xYri3 FjEg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=GxoT1U8gk6NApziuwmbCdtrtydUDrNAn08O/sRw2V60=; fh=jFkW6w4fq9o3CWnganXTHXlilPNWPocfTf28zwWSw0M=; b=ViuRr07uo49L0itdPZetZ0Lw7KbtbpeJuw2hX0G0OxW8iGTA/oNh/z3Ou5IQ6mwxFA W1SAiABqdjNeMQ7piEOF2sgNiQbRpHaSlSNmGNaSM/E6U44FRCgw5ZOPjlsXQhDF5kug 5+wpyKExbKnJo9Gh7dq/k8nL1pMZgbWjIH7aF5SL3Ditc0ak1zMKMjPXYlNRnhIeBsZS YJeKNWo/J76cniVkrj7j29qS22eahukZ9V8YypXqUMuA42Og2fH2Zh+TX6qaAQj8p0pv P4Sx9hGDkbk8h5GH+7R4wSYLq9AYX3EE0mClGU3U0e106L/+slFjKXyJVg6DJpQbMLiL nSJg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=GzUzYBd+; arc=pass (i=1 spf=pass spfdomain=bytedance.com dkim=pass dkdomain=bytedance.com dmarc=pass fromdomain=bytedance.com); spf=pass (google.com: domain of linux-kernel+bounces-30748-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30748-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id kq14-20020a056a004b0e00b006d9a6003c6asi5026667pfb.253.2024.01.18.19.53.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 19:53:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-30748-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=GzUzYBd+; arc=pass (i=1 spf=pass spfdomain=bytedance.com dkim=pass dkdomain=bytedance.com dmarc=pass fromdomain=bytedance.com); spf=pass (google.com: domain of linux-kernel+bounces-30748-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30748-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 1C93CB22EEF for ; Fri, 19 Jan 2024 03:53:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E54FB20FD; Fri, 19 Jan 2024 03:53:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="GzUzYBd+" Received: from mail-oo1-f53.google.com (mail-oo1-f53.google.com [209.85.161.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 05DDA184E for ; Fri, 19 Jan 2024 03:53:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705636401; cv=none; b=BoDlxHZLJEf3kmys53hoO4NJRp0w6CeZCsx/b1BgUevyN2Df0vQh6f85ci6727JHE/9YPeJtxdaooOIOEjz49K2zXsuTnr0s4Azh9z1vhJKZrPu7i5B5DWsZX/I74W+7EhlcxqpLE2egogkHkcfIAGb2P1QX3RtoNX+/ot0n6QM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705636401; c=relaxed/simple; bh=aWx0wpjrgEPLkK2IWMjjp4xx+BMTHqUg034HB89LlKE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=eM5kr5xi2MTuTDlsEia6C1jo9QmJYDH7Z/c+IKczVcpNt99w+vhKoZszWQRq1m82UBW6kamiQ8pmKTmfMcISm3j0lRahz3JZ/QJoLC1TEWflG8i8ZpkIurDKzt2BCQePQiRF9VDBg9idn/GRl4XFDMeENxanW+vho2FS3FBST2I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=GzUzYBd+; arc=none smtp.client-ip=209.85.161.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Received: by mail-oo1-f53.google.com with SMTP id 006d021491bc7-59927972125so170843eaf.3 for ; Thu, 18 Jan 2024 19:53:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1705636399; x=1706241199; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=GxoT1U8gk6NApziuwmbCdtrtydUDrNAn08O/sRw2V60=; b=GzUzYBd+tVsQQff/ZyOeA5Chn98E7CBpQoSIAMY/xCRVyYUNECHXvZfURM9j/mmuX2 CY74pj0W07T9euJ7KR5YT6HzH7F6WK/niVOhB2GDJz9lO7k6cJy/tbEKtal+rg40Wxxs a+SYtaAAps6n6u9map/SLmOuTcJU/R6dLnkHL4zy3q7w88M8QyxSQrpNebK54KXBHZcD sybYeCA4qc05N6lCo4H/s3Gznw56UjIZXlKN9PO13+PFvHnKypfI6JZT4fqDR3aqiHXr x3quqUfLUebWaXetU21qWDXHAjdLFADcrvzX0Dbz4yOvBBLUMlW7vc5GWyhVNk5H+Tm7 NdkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705636399; x=1706241199; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GxoT1U8gk6NApziuwmbCdtrtydUDrNAn08O/sRw2V60=; b=t3NQEPIkLY0YG1vpZD/EXPlUYKl6Vx8BsahULT/2sLZm9n2X+Wa/IY5pdvsTu6qs0d KFvsmpOVyFY7TjlxCDzFDK5xXYo9+pcfJOrGkZtnBGZjnHIuZ53mSs2KKkYRf07xA6Ks UOyNsWYkPgkfzU3NSD4a2TID2EI3GJFmGUY8exzPhDei7zIsWmfcTO9eThcC/LoDY2PK HySMnRNJAGo9+K4o6gAC34ZiOEOFlynMPh46eQa9K46ZRRHIB8XsbkdcytWzNCSCnaVN ecyaT5tqKCf7IEXX+xFMjLoHTEaCQqAID+ubF4nTtsdYAMVofzWjVcvmLXOc4jSZZk6h z/ug== X-Gm-Message-State: AOJu0YzG5LDUnq6A0QcYmw4LboMdQqTyNut8del+vsiZifVuXAubhEvt uoT+Omn0wud3vudfToSAcovSiNLYWtnnIDUXV3a+p7sQoR8pxd/ZM/iuA+piwaI= X-Received: by 2002:a05:6359:b87:b0:174:c9a0:cf99 with SMTP id gf7-20020a0563590b8700b00174c9a0cf99mr1694951rwb.57.1705636398851; Thu, 18 Jan 2024 19:53:18 -0800 (PST) Received: from [10.254.224.1] ([139.177.225.241]) by smtp.gmail.com with ESMTPSA id pd5-20020a17090b1dc500b0028c5585fb41sm2705415pjb.45.2024.01.18.19.53.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 18 Jan 2024 19:53:18 -0800 (PST) Message-ID: Date: Fri, 19 Jan 2024 11:53:12 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/3] mm/slub: directly load freelist from cpu partial slab in the likely case Content-Language: en-US To: "Christoph Lameter (Ampere)" Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com>, Joonsoo Kim , Vlastimil Babka , Pekka Enberg , Andrew Morton , Roman Gushchin , David Rientjes , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20240117-slab-misc-v1-0-fd1c49ccbe70@bytedance.com> <20240117-slab-misc-v1-1-fd1c49ccbe70@bytedance.com> <76641777-1918-2b29-b6aa-bda9b5467aa3@gentwo.org> <412b8618-0941-4d9d-85df-ee480695e7f7@bytedance.com> From: Chengming Zhou In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 2024/1/19 06:14, Christoph Lameter (Ampere) wrote: > On Thu, 18 Jan 2024, Chengming Zhou wrote: > >> So get_freelist() has two cases to handle: cpu slab and cpu partial list slab. >> The latter is NOT frozen, so need to remove "VM_BUG_ON(!new.frozen)" from it. > > Right so keep the check if it is the former? > Ok, I get it. Maybe like this: diff --git a/mm/slub.c b/mm/slub.c index 2ef88bbf56a3..7fa9dbc2e938 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -3313,7 +3313,7 @@ __update_cpu_freelist_fast(struct kmem_cache *s, * * If this function returns NULL then the slab has been unfrozen. */ -static inline void *get_freelist(struct kmem_cache *s, struct slab *slab) +static inline void *get_freelist(struct kmem_cache *s, struct slab *slab, int frozen) { struct slab new; unsigned long counters; @@ -3326,7 +3326,7 @@ static inline void *get_freelist(struct kmem_cache *s, struct slab *slab) counters = slab->counters; new.counters = counters; - VM_BUG_ON(!new.frozen); + VM_BUG_ON(frozen && !new.frozen); new.inuse = slab->objects; new.frozen = freelist != NULL; @@ -3440,7 +3440,7 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, if (freelist) goto load_freelist; - freelist = get_freelist(s, slab); + freelist = get_freelist(s, slab, 1); if (!freelist) { c->slab = NULL; @@ -3498,18 +3498,19 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, slab = slub_percpu_partial(c); slub_set_percpu_partial(c, slab); - local_unlock_irqrestore(&s->cpu_slab->lock, flags); - stat(s, CPU_PARTIAL_ALLOC); - if (unlikely(!node_match(slab, node) || - !pfmemalloc_match(slab, gfpflags))) { - slab->next = NULL; - __put_partials(s, slab); - continue; + if (likely(node_match(slab, node) && + pfmemalloc_match(slab, gfpflags))) { + c->slab = slab; + freelist = get_freelist(s, slab, 0); + stat(s, CPU_PARTIAL_ALLOC); + goto load_freelist; } - freelist = freeze_slab(s, slab); - goto retry_load_slab; + local_unlock_irqrestore(&s->cpu_slab->lock, flags); + + slab->next = NULL; + __put_partials(s, slab); } #endif