Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2376503ybi; Sun, 9 Jun 2019 10:12:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqy/9C4yk6ZtF8Eal/Xi0hzNzFrfQ74vMMkJE3vA96HPoAvvw0T3qrVXHsqkD/WQFyRX60/5 X-Received: by 2002:a17:90a:b00b:: with SMTP id x11mr17182887pjq.120.1560100321145; Sun, 09 Jun 2019 10:12:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560100321; cv=none; d=google.com; s=arc-20160816; b=pRJEzIvuas5uwE3wF2FFjeb0FSJ0CMoFiijFrDAiguvdb8AGJsQqehpDRS+FYNxMN5 mF/JP3Knl9NoTfzTm0oce4P8Mxymh/60wLxdJ+tdsrqgKvhlxfD/v2RRx29OSpXPvBQY fk33/riy6H0DIuzRboplRAQWnv0Y92koTd3vmt/y4XKuD/6lG8fNs3DRxZFuzNvfRCv4 CFjCDYAizKXmlLTqOVrWgMv+haLq+YPG4o//+BUS+uhi9Ds+kzYa5piB0FrBbof6C5aV QQ8uqcw8Oe0jpogEEY/ii4vco0HUWuik1/vm9t9O0ytg/ydKm3iqF6sVVstFRlXNehZE I9zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=SVFb92jStOUm7FrDt2zzfDZopbwt0k6o8Y+bNfKiHmE=; b=Zrw5eOJ0OdylPMgFkroLh8Sf3nWQcbbQrEqeUmvwsf78VCIDAug1rHngI/eKQhm4oe hSMx8pUL6nX1OnOXW/HEdJHzyyku9uWWiK/pTMK2MUr3KHf3Du6l11ucrw8FYwDrinH+ sAU893Wx8Y3amRc0ksEeuff78x566z8ZHiFjDXpgGZpqFy/KKqPffPdcTfAFv5R0unnJ 0S4D60nx98nfHF0RGZJ9RedgxYTqB1T13sEL/bRU1Ra/9QYfotkF3BdUvmLT26JjHt0+ gvwQx7EhnrMynPb+MA5WwXlhDgDxo/B3DaOEYVFkwoyO+loUTVvxmQ4N/bJvBcRJStlg vjcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=h4YLVhvO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o3si7872921pld.102.2019.06.09.10.11.45; Sun, 09 Jun 2019 10:12:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=h4YLVhvO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388845AbfFIRJK (ORCPT + 99 others); Sun, 9 Jun 2019 13:09:10 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:43223 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728617AbfFIRJJ (ORCPT ); Sun, 9 Jun 2019 13:09:09 -0400 Received: by mail-lj1-f194.google.com with SMTP id 16so5794845ljv.10 for ; Sun, 09 Jun 2019 10:09:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=SVFb92jStOUm7FrDt2zzfDZopbwt0k6o8Y+bNfKiHmE=; b=h4YLVhvOorSOqenh/f1Bfik5jof3C1oJr99L3BAEiC30vXLOQLOhta3DqN4cFuMrCR kSmzIPGSe/Df4sups5Foy+UBkAZH4ekAUvk9e6N+B66TEvfAFoydIYEVuuwY0NhkwWQ3 nJLOuQRDuyTRYaLHNZ/ho/m/l2oLJGg6FaQ3C6WST9e48H+dneVBxl/uig9D7xxGUMzs 4CZGlQ75U1yTg3/yuLOzHmedlR6sJdUekPgbSJ957WA4J970PfsjWWxfPTKUY77cLODe IPUjzyXe4PSD22yUDhEx7M9aB7b7lcWkbcDJggLnP9oubHGHtwHHZYY6buIeEGacHViB H7zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=SVFb92jStOUm7FrDt2zzfDZopbwt0k6o8Y+bNfKiHmE=; b=LNq9QsKDpWlzOD9gjne5OBhcokn+G6wsFPkViC6D/Wd7JKk7MxRWFKrnaLicvyC0RW Ou9dFthLsK38u7AiCyx5hgKHP+le/hF0Epbd2CuMd/6t0vvGjaEyeZI6nhpZek9Ffklu 2UqSHtNkDX3sYl93o3f5gaz357e/TdI9Ty3jwD1LbUkLcXEpp+9QHYBeh5m2J6m6lJnP 3lcR0/D8nXz5VhMEpZvSqLXj+C67NGrGBkzWby7O+s/JbfTtD9N1dWS2z+4Z6aITPRsq CAvqD2E2U+NF+d92FvtxdjQM+h6aIFfQVFMUM1klxCFygLW+wkRKqVZIpJVBEn+uRfnx 6bDA== X-Gm-Message-State: APjAAAUFqShF71BqRSvrvFCVIxhZc5ZNzjHzn83kfk7msmf7tH+aN3X3 Wk1pJRpuZ4CHqmTCij4uoDhunSq5Mkg= X-Received: by 2002:a2e:9e07:: with SMTP id e7mr15412972ljk.55.1560100147772; Sun, 09 Jun 2019 10:09:07 -0700 (PDT) Received: from esperanza ([176.120.239.149]) by smtp.gmail.com with ESMTPSA id x29sm1513881lfg.58.2019.06.09.10.09.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jun 2019 10:09:07 -0700 (PDT) Date: Sun, 9 Jun 2019 20:09:04 +0300 From: Vladimir Davydov To: Roman Gushchin Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, Johannes Weiner , Shakeel Butt , Waiman Long Subject: Re: [PATCH v6 08/10] mm: rework non-root kmem_cache lifecycle management Message-ID: <20190609170904.nxa2rb6inkvx3geg@esperanza> References: <20190605024454.1393507-1-guro@fb.com> <20190605024454.1393507-9-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190605024454.1393507-9-guro@fb.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 04, 2019 at 07:44:52PM -0700, Roman Gushchin wrote: > Currently each charged slab page holds a reference to the cgroup to > which it's charged. Kmem_caches are held by the memcg and are released > all together with the memory cgroup. It means that none of kmem_caches > are released unless at least one reference to the memcg exists, which > is very far from optimal. > > Let's rework it in a way that allows releasing individual kmem_caches > as soon as the cgroup is offline, the kmem_cache is empty and there > are no pending allocations. > > To make it possible, let's introduce a new percpu refcounter for > non-root kmem caches. The counter is initialized to the percpu mode, > and is switched to the atomic mode during kmem_cache deactivation. The > counter is bumped for every charged page and also for every running > allocation. So the kmem_cache can't be released unless all allocations > complete. > > To shutdown non-active empty kmem_caches, let's reuse the work queue, > previously used for the kmem_cache deactivation. Once the reference > counter reaches 0, let's schedule an asynchronous kmem_cache release. > > * I used the following simple approach to test the performance > (stolen from another patchset by T. Harding): > > time find / -name fname-no-exist > echo 2 > /proc/sys/vm/drop_caches > repeat 10 times > > Results: > > orig patched > > real 0m1.455s real 0m1.355s > user 0m0.206s user 0m0.219s > sys 0m0.855s sys 0m0.807s > > real 0m1.487s real 0m1.699s > user 0m0.221s user 0m0.256s > sys 0m0.806s sys 0m0.948s > > real 0m1.515s real 0m1.505s > user 0m0.183s user 0m0.215s > sys 0m0.876s sys 0m0.858s > > real 0m1.291s real 0m1.380s > user 0m0.193s user 0m0.198s > sys 0m0.843s sys 0m0.786s > > real 0m1.364s real 0m1.374s > user 0m0.180s user 0m0.182s > sys 0m0.868s sys 0m0.806s > > real 0m1.352s real 0m1.312s > user 0m0.201s user 0m0.212s > sys 0m0.820s sys 0m0.761s > > real 0m1.302s real 0m1.349s > user 0m0.205s user 0m0.203s > sys 0m0.803s sys 0m0.792s > > real 0m1.334s real 0m1.301s > user 0m0.194s user 0m0.201s > sys 0m0.806s sys 0m0.779s > > real 0m1.426s real 0m1.434s > user 0m0.216s user 0m0.181s > sys 0m0.824s sys 0m0.864s > > real 0m1.350s real 0m1.295s > user 0m0.200s user 0m0.190s > sys 0m0.842s sys 0m0.811s > > So it looks like the difference is not noticeable in this test. > > Signed-off-by: Roman Gushchin Acked-by: Vladimir Davydov