Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp927021pxb; Thu, 15 Apr 2021 09:37:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwCigVv+5/ZzoHfTJ4qynZo+/3ml2ELRcBAtdil34eOokf9hc5r/q+citw9jfZwzKwoJ7yP X-Received: by 2002:a17:906:95cb:: with SMTP id n11mr4434490ejy.251.1618504671721; Thu, 15 Apr 2021 09:37:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618504671; cv=none; d=google.com; s=arc-20160816; b=VBR6IXAqi5xEaq+Ug0ikDu6KCCZv4tjpBMrfDnvGleyDPoVD+bodhUl3SS0SyFvtgx qs/JvAZ+8FQecILp6fcT4Dh+6MHy4ggvKQTjQnJUuO8ntwm6sYoHM9TCXTJD4ADlmN06 rBI8YdEUGdCM+POsUtqdwGGr4NcVobFr56M/MgEZURn/6+W70W+Ja/Ymy+EiN9n3XyBZ dnRHA2NsK/i9gVXAKGVCknoc6m9rfk7zwkeGRSPuENeMhV1Jv6hRwixCNuO2rrLtFo+0 Pe3yjRwUJ4TcZkxP5F7uHaOoXBX7U9CI+Q6A0dUa1Ce079c1Ceyay/o9WvNwkhvT/+fA xfZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:references:cc :to:subject:from:dkim-signature; bh=s47wUvhDxo7f8LaX+UuV/f8OqzaAqCVXK0vtBt6gLnc=; b=wsBWOyIk5M+WarAj2FM4GillHSpYHZ5rtxKAMvL5pqa78cRghgmhrBKy6y/+zOoIzQ qfF1b9wawqv4fmg4h4dse/SknfMikPdtGyqIrKLouoTgtvTSOudCkWr/lRCj6tuh/3V3 g26UGGpKloUER9+KYe/zVh25tFyQ77j0hay39gDur9C1MegngTFq5gk0UhRC0MvLLv3S qcJDyXABxS3SA0rykEebRZUFj3c+RT6yFpe0TpXi3TGlyI49RBr52XSiLpolIVkErfud RrDXTnqRCx4X2SiaZuar4bMF0TjVpdcYalpOgfZL19tBxeyyTOBvGQ1jhMoaF8b9oRtu b5VA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FYmibwOv; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w9si3501350edi.363.2021.04.15.09.37.16; Thu, 15 Apr 2021 09:37:51 -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=@redhat.com header.s=mimecast20190719 header.b=FYmibwOv; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232759AbhDOQgO (ORCPT + 99 others); Thu, 15 Apr 2021 12:36:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:37737 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231549AbhDOQgN (ORCPT ); Thu, 15 Apr 2021 12:36:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618504550; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s47wUvhDxo7f8LaX+UuV/f8OqzaAqCVXK0vtBt6gLnc=; b=FYmibwOvsQ/3bq1uvCQrILUCuFotTsoUHM7QDc3LeHXDG5PFG8618dMMyPnnW78N1XUO6j OLBERX4I/YSBS2o3F8ZojIWrhRDhIqK5/18pAOH6tGXfF9iEPK+4zJ7yKABbSrig6hDB5C fSK9yQIAoRznQjm95c2Yxjol/4gkDUU= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-186-SlEYoF4mPkeaCFV_FM-fLA-1; Thu, 15 Apr 2021 12:35:48 -0400 X-MC-Unique: SlEYoF4mPkeaCFV_FM-fLA-1 Received: by mail-qk1-f200.google.com with SMTP id 79so1869372qkm.20 for ; Thu, 15 Apr 2021 09:35:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=s47wUvhDxo7f8LaX+UuV/f8OqzaAqCVXK0vtBt6gLnc=; b=cN9iyokOFXG8Bhbek1L+bwZTFSqCTC/ji/QCiLDvP2lP6/6u3FmMbDG4WPMXjGNRys 461jb/lTJPEd5u0NXe51k+Dr5RNdxBDdfVpPilTDdjiQxlo837bsa90xYURm5Q7UVVh0 v7/RchzZa4PxWEwfpkl7F3tHKndmJij/QCF77OKwrilkBIIZ0sq4Y8tebIqlPPl1Wnfs /s9aLy2M4f9yE2VWIKpPA0TpRfZEkmn/SLbXw8zKsGo+9kwx822zoTXx0HNd7fmAyXSk Wl9Qmtu160yIhT8/c+hJTjiUEKqB9aaBx1joGpEiqweIsAlBp9Z1bymotpj8mjS7S970 LKjQ== X-Gm-Message-State: AOAM531F4vJf9GEKCoOOSCg225VE5ivBL+rDc3TbMelQYqOjwABERd4C fSTLokHHH5L6y7jWw83n7Cusa60NRD4avSrhmvUxNdM9SZOE4txg9lPL8qhKV8mJlQJ9qVe8Y3G tFnxBjcuHbWK9pu6C+PjOhclG X-Received: by 2002:a05:622a:14c6:: with SMTP id u6mr3732885qtx.125.1618504547885; Thu, 15 Apr 2021 09:35:47 -0700 (PDT) X-Received: by 2002:a05:622a:14c6:: with SMTP id u6mr3732852qtx.125.1618504547668; Thu, 15 Apr 2021 09:35:47 -0700 (PDT) Received: from llong.remote.csb ([2601:191:8500:76c0::cdbc]) by smtp.gmail.com with ESMTPSA id 26sm2171153qtd.73.2021.04.15.09.35.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 Apr 2021 09:35:47 -0700 (PDT) From: Waiman Long X-Google-Original-From: Waiman Long Subject: Re: [PATCH v3 2/5] mm/memcg: Introduce obj_cgroup_uncharge_mod_state() To: Johannes Weiner Cc: Michal Hocko , Vladimir Davydov , Andrew Morton , Tejun Heo , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Vlastimil Babka , Roman Gushchin , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Shakeel Butt , Muchun Song , Alex Shi , Chris Down , Yafang Shao , Wei Yang , Masayoshi Mizuma , Xing Zhengjun References: <20210414012027.5352-1-longman@redhat.com> <20210414012027.5352-3-longman@redhat.com> Message-ID: <1c85e8f6-e8b9-33e1-e29b-81fbadff959f@redhat.com> Date: Thu, 15 Apr 2021 12:35:45 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/15/21 12:30 PM, Johannes Weiner wrote: > On Tue, Apr 13, 2021 at 09:20:24PM -0400, Waiman Long wrote: >> In memcg_slab_free_hook()/pcpu_memcg_free_hook(), obj_cgroup_uncharge() >> is followed by mod_objcg_state()/mod_memcg_state(). Each of these >> function call goes through a separate irq_save/irq_restore cycle. That >> is inefficient. Introduce a new function obj_cgroup_uncharge_mod_state() >> that combines them with a single irq_save/irq_restore cycle. >> >> @@ -3292,6 +3296,25 @@ void obj_cgroup_uncharge(struct obj_cgroup *objcg, size_t size) >> refill_obj_stock(objcg, size); >> } >> >> +void obj_cgroup_uncharge_mod_state(struct obj_cgroup *objcg, size_t size, >> + struct pglist_data *pgdat, int idx) > The optimization makes sense. > > But please don't combine independent operations like this into a > single function. It makes for an unclear parameter list, it's a pain > in the behind to change the constituent operations later on, and it > has a habit of attracting more random bools over time. E.g. what if > the caller already has irqs disabled? What if it KNOWS that irqs are > enabled and it could use local_irq_disable() instead of save? > > Just provide an __obj_cgroup_uncharge() that assumes irqs are > disabled, combine with the existing __mod_memcg_lruvec_state(), and > bubble the irq handling up to those callsites which know better. > That will also work. However, the reason I did that was because of patch 5 in the series. I could put the get_obj_stock() and put_obj_stock() code in slab.h and allowed them to be used directly in various places, but hiding in one function is easier. Anyway, I can change the patch if you think that is the right way. Cheers, Longman