From patchwork Thu Oct 12 09:29:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 115595 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp1724944qgn; Thu, 12 Oct 2017 02:32:16 -0700 (PDT) X-Google-Smtp-Source: AOwi7QCVmZc5gkP0I075YaEOzz/3DJ/TGsrWIlo3tCe17oqyAk49HFPtX84IG9WfPlYsjRYm28Di X-Received: by 10.98.109.69 with SMTP id i66mr1681429pfc.200.1507800736123; Thu, 12 Oct 2017 02:32:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507800736; cv=none; d=google.com; s=arc-20160816; b=su88/PR4u5uwDlg3jTAJlbyGC21QEg0tNehITnHi/E1gRcj8Zlx69HNTD0I5v/Z7/O eMfZJrNqeV2W2P1PCOxNTn1CzvytNfktWTRu/OJ7HyYDjks2ogb83rKRX2p/DOE81EFH cM6zjTaoU5HL7H6oYEBoeTA6vs/AOJCyN1eLFtzHK/oSB61WWoFboTGnGIA0vkhpn/Tq +pWusrARlB2JVWNt/erl4OOM6M/xiiv9RaEsFuzSS+7kRo0WBRB4DXQZwzF0xkzz2MLT ppv2RSuFpx1brQYxBMvir62RtSOaQ+NAyiCiybfre+0kqjOfy8AgS8SMrsXNRQtUcYjT U+iA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter:arc-authentication-results; bh=D4sSchtUnb4m/GkVFB4H7PeTMPS6eZ3tm1q9+YSdhgg=; b=oDDiv/RAq9ZPghuiIrNcbWb6mFB92KF1Lj3Jj+8BTk9UCU0BqAQGXD0AZsNEq9n1jH 6/CekLGgfo0JBXXsh5hOSwojSykNSePx3egPAIqXdUgUoJF+WztAcmxh6lemvWuSI1ot mJcCCghA7AsekmOjikBRAoLL2hZgwTw83SUaGjltX8G8XmI1TlPHtF9cf+pwBiw6Maga syhuNGqKWHElh9cFP+YUOATgCUr7MONJ3wIOV9MxCXYkwM5pppJ1ZjawkAifrvoGDdrv q8NNlKHmXwmgTCmtO2qSd0UUMTD1Agnj4Sf33jHsWIRA8q/Dl0BFQYoGJbHYttOIYER2 fCKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=U3Hti4PM; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z11si11744274plo.129.2017.10.12.02.32.15; Thu, 12 Oct 2017 02:32:16 -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=@nifty.com header.s=dec2015msa header.b=U3Hti4PM; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756649AbdJLJcO (ORCPT + 27 others); Thu, 12 Oct 2017 05:32:14 -0400 Received: from conuserg-11.nifty.com ([210.131.2.78]:35352 "EHLO conuserg-11.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756573AbdJLJcL (ORCPT ); Thu, 12 Oct 2017 05:32:11 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-11.nifty.com with ESMTP id v9C9Tx4w001697; Thu, 12 Oct 2017 18:29:59 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-11.nifty.com v9C9Tx4w001697 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1507800600; bh=D4sSchtUnb4m/GkVFB4H7PeTMPS6eZ3tm1q9+YSdhgg=; h=From:To:Cc:Subject:Date:From; b=U3Hti4PM1R5gaE938U3Sfggvr0+8wZRShh1iTGepMCJ/WwvVrtuqT8P1XufnuNB65 ED/AsXil4x7x3ip2p8wDuxeuFrWjL4qS+8h1u8m+ZSwjSv6CQpaE2cnxRxb8NyBkT1 XUWaMkwSbzF4kCb+zK9ht0Eo+9p2s0u9LnawBuHGg0SYxcEhX62S2b4Fr5olo/6JKH Jl7w46HQE9Qd0UyL+iYyOOMQ1vc6dz+xBIbh/rhZ7AOkOHc/kBfrZOgdnaZtPMtKvy NklJmWXnQuupEHX6MhJ6+D3DCc4CFV/dSoghh/7Zp18JsDAH49WfogFndSUC7Usfqk 4DRuYy9FZWDgQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Douglas Anderson , Masahiro Yamada , Marcin Nowakowski , Matthias Kaehlcke , Cao jin , Arnd Bergmann , Mark Charlebois , linux-kernel@vger.kernel.org, =?utf-8?q?Jan-Simon_M=C3=B6ller?= , Josh Poimboeuf , Ingo Molnar Subject: [PATCH] kbuild: shrink Makefile cache when it exceeds 1000 lines Date: Thu, 12 Oct 2017 18:29:29 +0900 Message-Id: <1507800569-30134-1-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The cache files are only cleaned away by "make clean". If you continue incremental builds, the cache files will grow up little by little. It is not a big deal in general use cases because $(call cc-option,...) in not added/deleted quite often. However, if you do build-test for various architectures, compilers, and kernel configurations, you will end up with huge cache files soon. The simple idea is to cut down the cache when it exceeds a certain limit. I wrote a simple method to check if nr_cache >= 1000. If it is, shrink it by "tail -500". This is not LRU strategy, but I hope it will work well enough. Signed-off-by: Masahiro Yamada --- If you have a better idea, please suggest it! scripts/Kbuild.include | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 4203fff..db81df3 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -99,9 +99,30 @@ cc-cross-prefix = \ # Include values from last time make-cache := $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/,$(if $(obj),$(obj)/)).cache.mk -$(make-cache): ; -include $(make-cache) +nr_cache := $(words $(filter __cached_%, $(.VARIABLES))) + +# Strip the last digit. Covert as follows: +# 0 -> +# 123 -> 12 +strip_last_digit = $(filter-out $1,$(firstword \ + $(sort $(foreach i,0 1 2 3 4 5 6 7 8 9,$(patsubst %$i,%,$1))))) + +# If cache exceeds 1000 lines, shrink it down to 500. The Least Recently Added +# lines are deleted. (not Least Recently Used, unfortunately) +# +# Evalucate [ ${nr_cache} -ge 1000 ] without relying on external tools. +# Check if nr_cache is not empty even after the last three digits are stripped. +ifneq ($(call strip_last_digit,$(call strip_last_digit,$(call strip_last_digit,$(nr_cache)))),) +.PHONY: $(make-cache) +$(make-cache): + tail -500 $@ > $@.tmp + mv $@.tmp $@ +else +$(make-cache): ; +endif + # Usage: $(call __sanitize-opt,Hello=Hola$(comma)Goodbye Adios) # # Convert all '$', ')', '(', '\', '=', ' ', ',', ':' to '_'