interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / collab / co8cache.om

195 lines · 3801 bytes Raw Blame History
1note collab/co8cache.om (ForgePatches): the raw-diff cache <tfdata>collab/<rid>/<base>-<head>.full.diff
2note holds at most cocap bytes in total: 2 GiB = 2147483648 bytes
3note (WolframLanguageEvaluator: UnitConvert[Quantity[2, "Gibibytes"], "Bytes"] -> 2147483648 bytes).
4note One diff file is at most 512 MiB (536870912). Eviction is least recently used by ctime, as
5note dl/dl.om does it: a cache hit chmods the file (which sets its ctime), and after every new file the
6note oldest files go until the total is at or under the cap.
7text tccdir "collab"
8global gckst uchar 128
9global gckp uchar 4096
10global gckpl ulong 1
11global gcksd uchar 256
12global gcksdl ulong 1
13global gcke uchar 16384
14global gcke2 uchar 16384
15global gcktot ulong 1
16global gckold uchar 4096
17global gckoldl ulong 1
18global gckoldc ulong 1
19fn cocap to ulong
20ret 2147483648
21end
22fn cocfmax to ulong
23ret 536870912
24end
25note ---- stat helpers (Linux arm64 stat: mode +16, size +48, ctime +104 s, +112 ns)
26fn cocst64 o ulong to ulong
27v = ulong 0
28for i ulong 8
29b = ulong get gckst add o i
30v = or v shl b mul i 8
31end
32ret v
33end
34fn cocst32 o ulong to ulong
35v = ulong 0
36for i ulong 4
37b = ulong get gckst add o i
38v = or v shl b mul i 8
39end
40ret v
41end
42note cocsize: size of the regular file gccf, -1 when it is missing or not a regular file
43fn cocsize to long
44r = stat gccf 0 get gccfl 0 gckst 0 128
45if lt r 0
46ret -1
47end
48if ne and cocst32 16 61440 32768
49ret -1
50end
51ret long cocst64 48
52end
53note coctouch: a cache hit; chmod sets the ctime the eviction orders by
54fn coctouch to void
55x = chmod gccf 0 get gccfl 0 384
56end
57note ---- path builder gckp
58fn cocpc c uchar to void
59n = get gckpl 0
60if lt n 4096
61put gckp n c
62put gckpl 0 add n 1
63end
64end
65fn cocpb to void
66put gckpl 0 0
67for i ulong len tfdata
68cocpc get tfdata i
69end
70for i ulong len tccdir
71cocpc get tccdir i
72end
73end
74fn cocpsub to void
75cocpb
76cocpc 47
77for i ulong get gcksdl 0 bound 256
78cocpc get gcksd i
79end
80end
81note ---- LRU eviction over <tfdata>collab/*/*
82fn cocevict to void
83for round ulong 256
84cocscan
85if le get gcktot 0 cocap
86ret
87end
88if eq get gckoldl 0 0
89ret
90end
91x = unlink gckold 0 get gckoldl 0
92end
93end
94fn cocscan to void
95put gcktot 0 0
96put gckoldl 0 0
97cocpb
98fd = fopen gckp 0 get gckpl 0 540672 0
99if lt fd 0
100ret
101end
102for it ulong 4096
103n = getdnts int fd gcke 0 16384
104if le n 0
105break
106end
107cocscn1 ulong n
108end
109x = fclose int fd
110end
111note cocscn1 n: each subdirectory (d_type 4, not dot-named) of <tfdata>collab
112fn cocscn1 n ulong to void
113p = ulong 0
114for it ulong 16384
115if ge add p 19 n
116break
117end
118rl = or ulong get gcke add p 16 shl ulong get gcke add p 17 8
119if eq rl 0
120break
121end
122if and eq get gcke add p 18 4 ne get gcke add p 19 46
123put gcksdl 0 0
124for i ulong 255
125c = get gcke add add p 19 i
126if eq c 0
127break
128end
129put gcksd i c
130put gcksdl 0 add i 1
131end
132cocdir
133end
134p = add p rl
135end
136end
137fn cocdir to void
138cocpsub
139fd = fopen gckp 0 get gckpl 0 540672 0
140if lt fd 0
141ret
142end
143for it ulong 4096
144n = getdnts int fd gcke2 0 16384
145if le n 0
146break
147end
148cocfile ulong n
149end
150x = fclose int fd
151end
152note cocfile n: each regular file (d_type 8) of the subdirectory
153fn cocfile n ulong to void
154p = ulong 0
155for it ulong 16384
156if ge add p 19 n
157break
158end
159rl = or ulong get gcke2 add p 16 shl ulong get gcke2 add p 17 8
160if eq rl 0
161break
162end
163if eq get gcke2 add p 18 8
164cocpsub
165cocpc 47
166for i ulong 255
167c = get gcke2 add add p 19 i
168if eq c 0
169break
170end
171cocpc c
172end
173cocfil1
174end
175p = add p rl
176end
177end
178note cocfil1: count the file in gckp, keep it as the eviction candidate when its ctime is oldest
179fn cocfil1 to void
180r = stat gckp 0 get gckpl 0 gckst 0 128
181if lt r 0
182ret
183end
184put gcktot 0 add get gcktot 0 cocst64 48
185ct = add mul cocst64 104 1000000000 cocst64 112
186if and ne get gckoldl 0 0 ge ct get gckoldc 0
187ret
188end
189n = get gckpl 0
190for i ulong n bound 4096
191put gckold i get gckp i
192end
193put gckoldl 0 n
194put gckoldc 0 ct
195end