 Okay Good afternoon. I'm Feng Bo-chun from Huawei today. I'd like to talk about Recurricives, read data logs and where to find them. This topic is a bit informative and times limited so we first go through the background and some of the information I would like to assume that you are all aware of it and if you have questions then you're welcome to approach me privately after this session and then Today I would like to talk about several topics the lock depth and where to find that log and how to assess it and what I do based on lock depth and how can we Detect lock depth. How can we detect that lock? First pretty simple That lock let's skip this part and basically if it's involved and it's It's relevant with deadlock and self-deadlock and ABBA deadlock To the lower right corner what we see here I'm gonna assume that you understand it and and Both in the A and B are in the locked up Status unable to proceed. ABBA can be expanded into a three deadlock sequence and also There are some deadlocks relevant with interots so basically we Can assume that's an expansion or a scaling off from ABBA and self-deadlock and if we're trying to suffer deadlock then No matter the code if there is deadlock then We will find a specific combination of codes and the interrupt will increase the possibility of deadlock code occurrence Well, if you Have a I will enable context and You drop the ABBA deadlock then there is a deadlock P0 RQ is enabled and there's a Spend lock a and There's a lock handler then they will handle lock B, but lock B is locked and In term they will spin lock a and then there is a deadlock And it will be expended to a three deadlock chain Locked up. What is it? Locked up is a deadlock assessing tools and it's a self-equipped tools in the kernel and still up around 2000 and It tried to minimize the occurrence of cold in deadlock and they will clarify they will classify different categories of Deadlocks and there is a concept of lock dependency to the right you can see P0 If there's a spin lock a and spin lock B, then we assume that A to B there is a lock dependence based on the dependence Then we will have a dependency graph It's pretty simple pretty straightforward We will see the lock dependency graph Is there any ring layout? and If there is a ring in the lock dependency graph and that will be a BBA deadlock then This is the code that is likely to appear the lock dependency graph It's gonna have this code So this case is a typical deadlock case Here I won't go into great details if you're interested then you're more than welcome to do more research on the condition of deadlock and Obviously In all our cases It's all spin lock and in kernel there are some other cases the lock that are dealing with it like the following Well, first let's focus and locked up So two we were lock One is recursive we were a lock unfair or a lock and the yellow The yellow arrow is The where the time progresses W1 writer 1 in red that means they won't get the lock And Next we have R2 reader 2 and they get the lock and If it's like this, then it's a non-comer rare lock If we have our writers keep coming that W1 will not get the lock It's unfair and the writer Will be very hungry and it's not very good and So all the rule a lock is fair really a lock. So these are two cases. So the yellow arrow is Where the time progress forward and R2 won't get the lock and And W1 will have high priority on getting the lock if it's like what's to the right If we don't have the writer Then R2 can get the lock So it's a river lock. It's different from the previous deadlock The reader get the log and if there is any writer, there's no other writer than the rest of the reader can also get the lock So there's the difference. So we can summarize in this graph saying that the recursive Real lock or deadlock they will have multiple readers and they will allowed recursive reader to have a Critical zone and one reader will not block the other readers and for a non recursive is river lock and also they will allow the multiple readers but They will not allowed recursive CS it's called non recursive obviously and the non recursive reader Will blocks other reader and they will have a signal This one Here you can see the R1 sometimes not are now blocking R2 but sometimes R1 when they get the lock Will block R2 with R1 now getting locked R2 will not get the lock as well So R1 will lock R2 with the non-relevant writers. So that's what we called one writer can block other writers One reader can block other readers. So this is the condition of blocking Differentiating different cases different scenarios So spin lock can be considered as the scenarios the only writers exist so If we view this graphic horizontally the recursive reader They will not block any other readers whether it's recursive or not and The recursive reader will not block other readers Guess it's recursive and it will block writers and The non recursive not no matter reader or writer Well first are from recursive aspects They will not allow CS zone and the writer is a non recursive lock That non recursive no matter it's reader or writer. They would block other reader And also other writer This is the block condition and Starting from here. This is what we called If we say this we were a lock is a non recursive we were a lock then if we're not Focusing on P2 but also P0 P1 then it's like The previous example, but if we want to trigger this that lock then we need P2 if there's no P2 P1 When they get the B then they can proceed to a if you're assessing Detaxing any that lock if we have to go through all you have to rule out all the possibilities of that lock and And If we got if the code have P0 and P1 then There's still the possibility of not being a deadlock and Relock It's a recursive lock then obviously This is not a deadlock a Recursive lock will not be blocked by another reader and If They have a P2 then P1 will still have to be A spin this can still get the lock. So this is none Deadlock and the lock that graph can be changed to this and A to B in B to A. There's a Ring and it's not that lock This one. This is deadlock itself and The writer will be blocked by reader the red lock will be blocked by P0 and If it's a ring layout Then we can see that here B to A is a WW This is not the initial lock B is a right lock and A is also a right lock and P1. That's the case So they have the same structs, but the Categories is different one is deadlock if the other is not so For the same struct they might have different categories of lock Sometimes it is determined as a deadlock. Sometimes it is that and Well, if it's a non recursive read lock Then if it's in the RQ context, it's a recursive deadlock They guarantee they have to guarantee that the handler can get lock and exceed ACP and it's a famous deadlock example. It's pretty special and This is deadlock example. This is read lock This is a bit different to the Upper right corner. It's a recursive deadlock the green bit and the other read lock is non recursive this is a deadlock and deadlock A If P0 get to B and P1 will not get the B Because if we have a not relevant readers then The blocking condition is that the P1 is when it's getting the B. It's a functional Reader lock if they have a Writer is there then the writers will first get the lock and then the readers will get the lock so the P1 read lock won't They won't be able to get the lock. It's a ring struct So later we're gonna touch upon that Next this is a not a deadlock this we just reverse the sequence So we can see P0 get a P1 get B P0 now once get the B It is possible. It is accessible. The lock is a recursive Relock and They have a P2 writer, but still they can get the lock. So this is not that lock itself so Locked up If you're just assessing the ring then we'll be missing some of the conditions of the deadlock We need to Make several changes first We have to make sure the existing deadlock is working lock that is working and also We had to handle the Q added lock and We have to consider the fast positive situation and If we have a false positive Detection to then people are not trusting the tool you can miss some of the deadlock is okay, but if you replace and false positive result and You might lose the trust from the Clients you had to guarantee the tool is trustworthy the lock that We must rule out the possibility of false positive. So This is very simply about how can we Detect recursive rewrite lock and We classify it as follows first we consider That we have three categories of real lock first our reader recursive reader and Non-recursive reader and writer in One dependency we're gonna have nine Combinations three times three so this is a direct sorting up According to the locked up conditions for a categories one shared locks Read their locks recursive or not and exclusive locks writer Lock or a plain spin locks and recursive readers and non recursive readers and writers It's represented by letters s e and s e r n and Recursive reader will be blocked by writers non recursive No matters reader or writer locks will be possibly blocked by other readers and other writers so if we Summarized it we got the following graphics R would be blocks by s and the others on The other occasion that would be blocked as but as means share e means exclusive R means Recursive and non recursive n means non recursive so We will lock the dependency we have four categories in this regard So why first SRN EN ER based on previous conditions and definitions we can easily understand that and I am saying that For the head of the dependency We only need to determine whether it's sure or exclusive for the tail We have to determine whether it's written recursive and non recursive so We will determine the block on this When we consider lock dependency, we are actually focusing on first If we're considering the dependency from a to b then a will be a lock What are the conditions it will block and water or other conditions they will be blocked Be if we say be can be blocked by the be in BC and then we can scale up and So For the codes in the lower right corner, we can come over this graphic From P zero we have a lock dependency SW Sorry, my mistake. It should be as n a to b dependency and B to a E and dependency And we have to define The two dependencies What is strong dependency we have to see How can we expand the locks dependency guarantee it is a deadlock all the way and How can we search in a lock dependency graph and guarantee that It's hadn't tail have a strong relations Very strong dependency See whether we can discover the ring or not If we can expand it we could if we can scale up then the dependency from a to b and b to see if it's meeting the following conditions that that means this is strong dependency and If it's only the last condition Transferred Only in the letter case is not a strong dependency all the other ones may have strong dependencies and we can explain this So I will introduce why we can all be in this one Because If this kind of situation happens the bee is a recursive reader Yes from a to be the bee is a recursive reader, but from B to C This is a shader reader and let's look back on the previous The recursive reader cannot be blocked by the recursive reader So there's not a strong dependency here If you can translate it into codes it means that P1 first chooses a and P2 chooses a bee B but he can still choose the bee from a to B Yeah, you can think about it Because other situations there will be the occurrence of blocking so this is the strong dependency We have we think it is Can transfer the relationship of the locks So the that log condition it means that the strong dependency chain forms a circle and The letter example it shows the code for the right one Yeah, it has the deadlock and because it doesn't have contain R at all And We can prove that it is also a deadlock Yeah, P1 get a and P1 get B and P2 get C and the system cannot continue So suppose this the log is a non-recursive the reader is a non-recursive one And I Have also proved it Yes, we want to prove that there's a kind of a circle a loop Not based on this definition we established a dependency graph if there's a kind of a loop occur happening so it You acquiesce to The possibility but it doesn't mean that the deadlock is definitely going to happen because you only need a very special Condition to make it happen to make the dialogue get triggered But for us we don't allow this possibility of deadlock occur because if that happens then the system will get stuck any time Yes, we don't want the deadlock Make it equate to the deadlock possibility. So suppose we have a strong dependency we can construct construct example In which the deadlock occurs And for the reverse once we can see that the deadlock of possibility means that We will have this condition for circular weight for the circular weight we can build a Loop gradually so there's must be a strong dependency circle and This is for the algorithm and this is for implementation We change the lock depth codes and also BMS search codes So as to make it to implement the strong dependency and we have done Some tests on it the code is show in the below. Yeah, you can check it There is a one good point is that When the lock depth just appears it has its own dialogue test It's called RQ reader recursion one Yeah, after I have added the algorithm it is wrong very well It proves that Yeah, my implementation algorithm is consistent with the previous thoughts Yeah today my topic is a bit complex and abstract, but I hope that There's a two points. I want to make first How can we expand the lock dependency relationship? We use the block condition the weight condition. So suppose I Have two lock dependencies Yeah, it's easy to find them if you can have this in the code then you can find it How can we expand it log? It's an issue and Another thing is that The dependency lock condition Yes, one reader can be blocked by another reader Yes, the other things they are very not not not complicated. I Mean the algorithm you can just Go and go deep depth yourself. So that's my presentation today. Thank you. So any questions? I Have a question because I haven't used Look that so is it a static or dynamic? Yeah, it's a good question. Is that Dynamic trace. Yes. It was built dynamically. It's Yes So that it won't affect the operation performance is going to work, but it's algorithm analysis is static. So is it blocked? Yes, so we still need to install it when we are writing it So can you go to the previous ones about the calculation based dependency? I Don't remember whether it's page 304 Oh Yes, go back or yes Backwards if you want to calculate the lock dependency It is done by the decipher machine So locked up this detection can be performed by the machine But when it's realized in the next kernel is a dynamic We use the to record what kind of lock it gets and This kind of method is not a time is static Go back to the dependency graph So is it a dynamically Generated yes in lock it is dynamically generated So it is Yes, the lock that will classify this locks It won't focus on the instances of this locks instead It focuses on the Structures locks it will categorize into it into one type But there is another CPU's lock is another type. Yeah, it has classified it you get the balance and We have this kind of classification method So after they have written the code that they have already done the classification and you just need to run it. Yes, so Yeah, that's basically the point. So I want to Mention that the lock depth is the more to do with the integration Yes, different systems use the different locks that when you want to integrate them, then there is a sound that lock Unpredictable happening so you feel but When you lock depth the information you actually avoid the that lock actually the that lock happens more during the integration process So it's more like a form of the distributor right because As the distributor dispatcher or the scheduler can just allocate the resources And yes, we can avoid this issue happening through the code. Thank you. I Like to ask you talk that lock depth Should avoid the false positive so any instances that There is a lock that lock but you can't detect it Yes for me Yes, we have this we have this that lock we cannot not detect the blocked lock and We it will think that it doesn't have a that lock Yes, you have realized on the branch Are you sure about it? Yes, they want to avoid the false positive Because they will classify this locks and depending on the ways to classify this if we give them to the very Few categories then for example, there's a dialogue the file system You can Regard the file in one file system as a disk and in this way If the file system They were just the one to get the lock all the time because you think it's a dialogue. So we that's why we want to classify it To avoid it being regarded as a dialogue But the sound case is there some that lock and We want to skip it, but I can't think of a very detailed case a specific case So, yes, I have a question so We have these pages right back It's like When we are just that want to get the back of it it ever says wait, it's bounded with weight, but the lock condition We can't capture it You mean the completion weight is the structure page they were right big It will wait for it to be right big and to make it to turn to off You mean the weight in Linux If you use a spin knock and you will have to wait for it for the wait to be clear to zero I'm not sure what you are mentioning. Yes, we have this kind of this progress in last year There's a sense of stuff. He can detect There's a dialogue with the condition of weight that is When you wait Actually wait with a lock But the lock died It doesn't take into consideration of this case. So it's actually way to with a lock. So This weight has a dependency and It has done up detection matter is very great, but it takes a longer time to Detect it. If you actually doubt, there's kind of Problem You have just to print the page again Yes, then you can find the issue Do you remember the name of the Samsung? Here's a Korean student. I don't his surname is Park of PARK And you can search for locked up. You can find him. He's very active in this area As I'm running out of time, so thank you very much